Skip to content

Commit

Permalink
Merge pull request #56 from jubalh/master
Browse files Browse the repository at this point in the history
Remove trailing whitespaces
  • Loading branch information
daf committed Jul 16, 2015
2 parents b596809 + f31b195 commit 1a796c4
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 174 deletions.
18 changes: 9 additions & 9 deletions src/ArgParser.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is from Nitrogen, an X11 background setter.
This file is from Nitrogen, an X11 background setter.
Copyright (C) 2006 Dave Foster & Javeed Shaikh
This program is free software; you can redistribute it and/or
Expand All @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "ArgParser.h"
#include "gcs-i18n.h"

bool ArgParser::parse
bool ArgParser::parse
(int argc, char ** argv) {
int count = 1;
bool retval = true;
Expand All @@ -36,7 +36,7 @@ bool ArgParser::parse
received_args["help"];
continue;
}

std::string::size_type minuspos;
if ((minuspos = key.find ("--")) == std::string::npos) {
// this is not an arg, append it
Expand All @@ -48,9 +48,9 @@ bool ArgParser::parse
extra_arg_str += key;
continue;
}

key = std::string (key, minuspos + 2);

std::string::size_type pos = key.find ('=');
if (pos != std::string::npos) {
key.erase (pos);
Expand All @@ -59,7 +59,7 @@ bool ArgParser::parse

std::map<std::string, Arg>::const_iterator iter;
Arg current;

if ((iter = expected_args.find (key)) == expected_args.end ()) {
// ignore this argument and set the error string
retval = false;
Expand All @@ -68,7 +68,7 @@ bool ArgParser::parse
} else {
current = iter->second;
}

if (current.get_has_arg () && !value.length ()) {
// this expects an arg, but has received none.
retval = false;
Expand All @@ -84,7 +84,7 @@ bool ArgParser::parse
error_str += key + _(" conflicts with another argument.") + "\n";
continue;
}

// save it.
received_args[key] = value;
}
Expand All @@ -109,7 +109,7 @@ std::string ArgParser::help_text (void) const {

bool ArgParser::conflicts (std::string key) {
std::vector< std::vector<std::string> >::const_iterator iter;

// Look through the exclusive iter. Cramped together to fit
// into 80 columns.
for (iter=exclusive.begin();iter!=exclusive.end();iter++) {
Expand Down
28 changes: 14 additions & 14 deletions src/ArgParser.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is from Nitrogen, an X11 background setter.
This file is from Nitrogen, an X11 background setter.
Copyright (C) 2006 Dave Foster & Javeed Shaikh
This program is free software; you can redistribute it and/or
Expand Down Expand Up @@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

class Arg {
public:
Arg ( std::string desc = "",
Arg ( std::string desc = "",
bool has_arg = false) {
set_desc (desc);
set_has_arg (has_arg);
Expand All @@ -39,21 +39,21 @@ class Arg {
std::string get_desc (void) const {
return desc;
}

bool get_has_arg (void) const {
return has_arg;
}

void set_desc (std::string desc) {
this->desc = desc;
}

void set_has_arg (bool has_arg) {
this->has_arg = has_arg;
}

~Arg () {};

protected:
std::string desc;
bool has_arg;
Expand All @@ -70,12 +70,12 @@ class ArgParser {
inline void register_option (std::string name, std::string desc = "", bool has_arg = false) {
expected_args[name] = Arg(desc, has_arg);
}

// makes two or more options mutually exclusive (only one or the other.)
inline void make_exclusive (std::vector<std::string> exclusive_opts) {
exclusive.push_back (exclusive_opts);
}

// returns the parsed map.
inline std::map<std::string, std::string> get_map (void) const {
return received_args;
Expand All @@ -85,18 +85,18 @@ class ArgParser {
inline std::string get_error (void) const {
return error_str;
}

inline std::string get_extra_args (void) const {
return extra_arg_str;
}

inline bool has_argument (std::string option) {
if (received_args.find (option) != received_args.end ()) {
return true;
}
return false;
}

inline std::string get_value (std::string key) {
std::map<std::string, std::string>::const_iterator iter = received_args.find (key);
if (iter != received_args.end ()) {
Expand All @@ -117,7 +117,7 @@ class ArgParser {
stream >> tmp_int;
return tmp_int;
}

// parses away.
bool parse (int argc, char ** argv);

Expand All @@ -127,8 +127,8 @@ class ArgParser {
protected:
// checks if the supplied key conflicts with an existing key.
bool conflicts (std::string key);
std::string error_str, extra_arg_str;

std::string error_str, extra_arg_str;
std::map<std::string, std::string> received_args;
std::map<std::string, Arg> expected_args;
std::vector< std::vector<std::string> > exclusive;
Expand Down
50 changes: 25 additions & 25 deletions src/Config.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is from Nitrogen, an X11 background setter.
This file is from Nitrogen, an X11 background setter.
Copyright (C) 2006 Dave Foster & Javeed Shaikh
This program is free software; you can redistribute it and/or
Expand Down Expand Up @@ -39,7 +39,7 @@ Config::Config()
m_sizey = 500;

m_icon_captions = false;

m_sort_mode = Thumbview::SORT_ALPHA;
}

Expand Down Expand Up @@ -120,10 +120,10 @@ bool Config::get_bg(const Glib::ustring disp, Glib::ustring &file, SetBG::SetMod
return false;

GKeyFile *kf = g_key_file_new();

GError *ge = NULL;
if ( g_key_file_load_from_file(kf, cfgfile.c_str(), G_KEY_FILE_NONE, &ge) == FALSE ) {

std::cerr << _("ERROR: Unable to load config file") << " (" << cfgfile << "): " << ge->message << "\n";
g_clear_error(&ge);
g_key_file_free(kf);
Expand All @@ -138,9 +138,9 @@ bool Config::get_bg(const Glib::ustring disp, Glib::ustring &file, SetBG::SetMod
std::cerr << _("Couldn't find group for") << " " << disp << "." << std::endl;
return false;
}

// get data

gchar *fileptr = g_key_file_get_string(kf, disp.c_str(), "file", NULL);
if ( fileptr ) {
file = Glib::ustring(fileptr);
Expand All @@ -151,7 +151,7 @@ bool Config::get_bg(const Glib::ustring disp, Glib::ustring &file, SetBG::SetMod
return false;
}
//error = true;

mode = (SetBG::SetMode)g_key_file_get_integer(kf, disp.c_str(), "mode", &ge);
if (ge) {
g_clear_error(&ge);
Expand All @@ -173,18 +173,18 @@ bool Config::get_bg(const Glib::ustring disp, Glib::ustring &file, SetBG::SetMod
tcol = color;
free(color);
}

// did not fail
// Glib::ustring tcol(color);
// free(color);
bgcolor.set(tcol);

g_key_file_free(kf);


// this function looks like less of an eyesore without all the
// failed trix.

return true; // success
}

Expand Down Expand Up @@ -227,7 +227,7 @@ bool Config::set_bg(const Glib::ustring disp, const Glib::ustring file, const Se

// must do complex removals if xinerama occurs
if (realdisp.find("xin_", 0, 4) != Glib::ustring::npos) {

if (realdisp == "xin_-1") {
// get all keys, remove all keys that exist with xin_ prefixes
gchar **groups;
Expand All @@ -238,7 +238,7 @@ bool Config::set_bg(const Glib::ustring disp, const Glib::ustring file, const Se
g_key_file_remove_group(kf, groups[i], NULL);

} else {

// a normal xinerama screen, therefore
// remove the big realdisp if it occurs
if (g_key_file_has_group(kf, "xin_-1"))
Expand All @@ -251,13 +251,13 @@ bool Config::set_bg(const Glib::ustring disp, const Glib::ustring file, const Se
g_key_file_set_string(kf, realdisp.c_str(), "file", file.c_str());
g_key_file_set_integer(kf, realdisp.c_str(), "mode", (gint)mode);
g_key_file_set_string(kf, realdisp.c_str(), "bgcolor", color_to_string(bgcolor).c_str());

// output it
Glib::ustring outp = g_key_file_to_data(kf, NULL, NULL);
std::ofstream outf(cfgfile.c_str());
outf << outp;
outf.close();

g_key_file_free(kf);

return true;
Expand All @@ -276,9 +276,9 @@ bool Config::get_bg_groups(std::vector<Glib::ustring> &groups) {
return false;

GKeyFile *kf = g_key_file_new();

if ( g_key_file_load_from_file(kf, cfgfile.c_str(), G_KEY_FILE_NONE, NULL) == FALSE ) {

// do not output anything here, we just want to know
g_key_file_free(kf);
return false;
Expand All @@ -292,10 +292,10 @@ bool Config::get_bg_groups(std::vector<Glib::ustring> &groups) {
for (unsigned int i=0; i<num; i++) {
res.push_back(Glib::ustring(filegroups[i]));
}

g_strfreev(filegroups);
groups = res;

g_key_file_free(kf);
return true;
}
Expand All @@ -306,13 +306,13 @@ bool Config::get_bg_groups(std::vector<Glib::ustring> &groups) {
* @return If it exists, or it was able to make it
*/
bool Config::check_dir() {

Glib::ustring dirname = Glib::build_filename(Glib::ustring(g_get_user_config_dir()), "nitrogen");
if ( !Glib::file_test(dirname, Glib::FILE_TEST_EXISTS ) )
if ( g_mkdir_with_parents(dirname.c_str(), 0755) == -1 )
// TODO: throw
return false;

return true;
}

Expand All @@ -328,10 +328,10 @@ Glib::ustring Config::color_to_string(Gdk::Color color) {
guchar blue = guchar(color.get_blue_p() * 255);

char * c_str = new char[7];

snprintf(c_str, 7, "%.2x%.2x%.2x", red, green, blue);
Glib::ustring string = '#' + Glib::ustring(c_str);

delete[] c_str;
return string;
}
Expand Down Expand Up @@ -427,7 +427,7 @@ bool Config::load_cfg()
if (cfgfile.empty())
return false;

// TODO: use load_from_data_dirs?
// TODO: use load_from_data_dirs?
Glib::KeyFile kf;
if (!kf.load_from_file(cfgfile))
return false;
Expand Down Expand Up @@ -462,7 +462,7 @@ bool Config::load_cfg()
else if (sort_mode == Glib::ustring("rtime"))
m_sort_mode = Thumbview::SORT_RTIME;
}

return true;
}

Expand All @@ -481,7 +481,7 @@ void Config::set_dirs(const VecStrs& new_dirs)
*
* Does not add if the passed dir already is in the list of dirs.
* Returns a boolean to indicate if this call resulted in an add.
* If it returns false, it didn't add a new one becuase it already
* If it returns false, it didn't add a new one becuase it already
* existed.
*/
bool Config::add_dir(const std::string& dir)
Expand Down
Loading

0 comments on commit 1a796c4

Please sign in to comment.