Skip to content

Commit

Permalink
Merge pull request #80 from l3ib/lxde
Browse files Browse the repository at this point in the history
LXDE (Pcmanfm) support (WIP)
  • Loading branch information
daf authored Oct 27, 2016
2 parents 34df913 + dc27d9c commit 665fca2
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 55 deletions.
15 changes: 12 additions & 3 deletions src/ArgParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

bool ArgParser::parse
(int argc, char ** argv) {
int count = 1;
std::vector<Glib::ustring> argVec;
for (int i = 0; i < argc; i++) {
argVec.push_back(Glib::ustring(argv[i]));
}

return this->parse(argVec);
}

bool ArgParser::parse
(std::vector<Glib::ustring> argVec) {
bool retval = true;

while (count < argc) {
std::string arg (argv[count++]);
for (std::vector<Glib::ustring>::const_iterator i = argVec.begin() + 1; i != argVec.end(); i++) {
std::string arg(*i);
std::string key = arg;
std::string value;

Expand Down
2 changes: 2 additions & 0 deletions src/ArgParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <vector>
#include <sstream>
#include <iostream>
#include <glibmm.h>

class Arg {
public:
Expand Down Expand Up @@ -120,6 +121,7 @@ class ArgParser {

// parses away.
bool parse (int argc, char ** argv);
bool parse (std::vector<Glib::ustring> argVec);

// returns the help text (--help)
std::string help_text (void) const;
Expand Down
23 changes: 2 additions & 21 deletions src/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "Config.h"
#include <glib/gstdio.h>
#include "gcs-i18n.h"
#include "Util.h"

/**
* Constructor, initializes default settings.
Expand Down Expand Up @@ -250,7 +251,7 @@ bool Config::set_bg(const Glib::ustring disp, const Glib::ustring file, const Se
// set data
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());
g_key_file_set_string(kf, realdisp.c_str(), "bgcolor", Util::color_to_string(bgcolor).c_str());

// output it
Glib::ustring outp = g_key_file_to_data(kf, NULL, NULL);
Expand Down Expand Up @@ -316,26 +317,6 @@ bool Config::check_dir() {
return true;
}

/**
* Converts a Gdk::Color to a string representation with a #.
*
* @param color The color to convert
* @return A hex string
*/
Glib::ustring Config::color_to_string(Gdk::Color color) {
guchar red = guchar(color.get_red_p() * 255);
guchar green = guchar(color.get_green_p() * 255);
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;
}

/**
* Gets the last saved position.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class Config {
VecStrs m_vec_dirs;
Thumbview::SortMode m_sort_mode;

Glib::ustring color_to_string(Gdk::Color color);

std::string get_bg_config_file() const { return get_file("bg-saved.cfg"); }
std::string get_config_file() const { return get_file("nitrogen.cfg"); }
std::string get_file(const Glib::ustring filename) const;
Expand Down
16 changes: 10 additions & 6 deletions src/NWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ void NWindow::sighandle_dblclick_item (const Gtk::TreeModel::Path& path) {
// find out which image was double clicked
Gtk::TreeModel::iterator iter = (view.store)->get_iter(path);
Gtk::TreeModel::Row row = *iter;
this->set_bg(row[view.record.Filename]);

// preview - set dirty flag
m_dirty = true;
// preview - set dirty flag, if setter says we should
m_dirty = this->set_bg(row[view.record.Filename]);
}

/**
Expand All @@ -188,7 +187,7 @@ void NWindow::apply_bg () {
Gtk::TreeModel::iterator iter = view.get_selected ();
Gtk::TreeModel::Row row = *iter;
Glib::ustring file = row[view.record.Filename];
this->set_bg(file);
bool saveToConfig = this->set_bg(file);

// apply - remove dirty flag
m_dirty = false;
Expand All @@ -198,7 +197,8 @@ void NWindow::apply_bg () {
Gdk::Color bgcolor = this->button_bgcolor.get_color();

// save
Config::get_instance()->set_bg(thedisp, file, mode, bgcolor);
if (saveToConfig)
Config::get_instance()->set_bg(thedisp, file, mode, bgcolor);

// tell the bg setter to forget about the first pixmap
bg_setter->clear_first_pixmaps();
Expand Down Expand Up @@ -282,8 +282,10 @@ bool NWindow::on_delete_event(GdkEventAny *event)
/**
* Queries the necessary widgets to get the data needed to set a bg. *
* @param file The file to set the bg to
*
* @returns If the dirty flag should be set or not
*/
void NWindow::set_bg(const Glib::ustring file) {
bool NWindow::set_bg(const Glib::ustring file) {

// get the data from the active items
SetBG::SetMode mode = SetBG::string_to_mode(this->select_mode.get_active_data());
Expand All @@ -292,6 +294,8 @@ void NWindow::set_bg(const Glib::ustring file) {

// set it
bg_setter->set_bg(thedisp, file, mode, bgcolor);

return bg_setter->save_to_config();
}

// leethax destructor
Expand Down
2 changes: 1 addition & 1 deletion src/NWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class NWindow : public Gtk::Window {
std::map<Glib::ustring, Glib::ustring> map_displays; // a map of current displays on the running instance to their display names
void set_default_display(int display);

void set_bg(Glib::ustring file);
bool set_bg(Glib::ustring file);

protected:
Glib::RefPtr<Gtk::ActionGroup> m_action_group;
Expand Down
Loading

0 comments on commit 665fca2

Please # to comment.