diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/LashProxy.cpp | 157 | ||||
-rw-r--r-- | src/LashProxy.hpp | 7 | ||||
-rw-r--r-- | src/Project.cpp | 42 | ||||
-rw-r--r-- | src/Project.hpp | 18 | ||||
-rw-r--r-- | src/ProjectList.cpp | 2 | ||||
-rw-r--r-- | src/ProjectPropertiesDialog.cpp | 35 | ||||
-rw-r--r-- | src/ProjectPropertiesDialog.hpp | 2 |
7 files changed, 126 insertions, 137 deletions
diff --git a/src/LashProxy.cpp b/src/LashProxy.cpp index 7bd9ec5..45941fc 100644 --- a/src/LashProxy.cpp +++ b/src/LashProxy.cpp @@ -61,6 +61,10 @@ struct LashProxyImpl { string id, string name); + void get_loaded_project_properties( + const std::string& name, + LoadedProjectProperties& properties); + bool _server_responding; Session* _session; LashProxy* _interface; @@ -472,7 +476,10 @@ unref: shared_ptr<Project> LashProxyImpl::on_project_added(const string& name) { - shared_ptr<Project> project(new Project(_interface, name)); + LoadedProjectProperties properties; + get_loaded_project_properties(name, properties); + + shared_ptr<Project> project(new Project(name, properties)); _session->project_add(project); @@ -494,6 +501,76 @@ LashProxyImpl::on_client_added( } void +LashProxyImpl::get_loaded_project_properties( + const string& name, + LoadedProjectProperties& properties) +{ + DBusMessage* reply_ptr; + const char* reply_signature; + DBusMessageIter iter; + DBusMessageIter dict_iter; + DBusMessageIter dict_entry_iter; + DBusMessageIter variant_iter; + const char* key; + const char* value_type; + dbus_bool_t value_bool; + const char* value_string; + + const char* const project_name_cstr = name.c_str(); + + if (!call( + true, + LASH_IFACE_CONTROL, + "ProjectGetProperties", + &reply_ptr, + DBUS_TYPE_STRING, &project_name_cstr, + DBUS_TYPE_INVALID)) { + return; + } + + reply_signature = dbus_message_get_signature(reply_ptr); + + if (strcmp(reply_signature, "a{sv}") != 0) { + error_msg((string)"ProjectGetProperties() reply signature mismatch. " + reply_signature); + goto unref; + } + + dbus_message_iter_init(reply_ptr, &iter); + + for (dbus_message_iter_recurse(&iter, &dict_iter); + dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_INVALID; + dbus_message_iter_next(&dict_iter)) { + dbus_message_iter_recurse(&dict_iter, &dict_entry_iter); + dbus_message_iter_get_basic(&dict_entry_iter, &key); + dbus_message_iter_next(&dict_entry_iter); + dbus_message_iter_recurse(&dict_entry_iter, &variant_iter); + value_type = dbus_message_iter_get_signature(&variant_iter); + if (value_type[0] != 0 && value_type[1] == 0) { + switch (*value_type) { + case DBUS_TYPE_BOOLEAN: + if (strcmp(key, "Modified Status") == 0) { + dbus_message_iter_get_basic(&variant_iter, &value_bool); + properties.modified_status = value_bool; + } + break; + case DBUS_TYPE_STRING: + if (strcmp(key, "Description") == 0) { + dbus_message_iter_get_basic(&variant_iter, &value_string); + properties.description = value_string; + } else if (strcmp(key, "Notes") == 0) { + dbus_message_iter_get_basic(&variant_iter, &value_string); + properties.notes = value_string; + } + break; + } + } + } + +unref: + dbus_message_unref(reply_ptr); +} + +void LashProxy::get_available_projects(list<ProjectInfo>& projects) { DBusMessage* reply_ptr; @@ -571,6 +648,14 @@ unref: } void +LashProxy::get_loaded_project_properties( + const string& name, + LoadedProjectProperties& properties) +{ + return _impl->get_loaded_project_properties(name, properties); +} + +void LashProxy::load_project(const string& project_name) { DBusMessage* reply_ptr; @@ -655,76 +740,6 @@ LashProxy::project_rename(const string& old_name, const string& new_name) } void -LashProxy::get_loaded_project_properties( - const string& name, - LoadedProjectProperties& properties) -{ - DBusMessage* reply_ptr; - const char* reply_signature; - DBusMessageIter iter; - DBusMessageIter dict_iter; - DBusMessageIter dict_entry_iter; - DBusMessageIter variant_iter; - const char* key; - const char* value_type; - dbus_bool_t value_bool; - const char* value_string; - - const char* const project_name_cstr = name.c_str(); - - if (!_impl->call( - true, - LASH_IFACE_CONTROL, - "ProjectGetProperties", - &reply_ptr, - DBUS_TYPE_STRING, &project_name_cstr, - DBUS_TYPE_INVALID)) { - return; - } - - reply_signature = dbus_message_get_signature(reply_ptr); - - if (strcmp(reply_signature, "a{sv}") != 0) { - _impl->error_msg((string)"ProjectGetProperties() reply signature mismatch. " + reply_signature); - goto unref; - } - - dbus_message_iter_init(reply_ptr, &iter); - - for (dbus_message_iter_recurse(&iter, &dict_iter); - dbus_message_iter_get_arg_type(&dict_iter) != DBUS_TYPE_INVALID; - dbus_message_iter_next(&dict_iter)) { - dbus_message_iter_recurse(&dict_iter, &dict_entry_iter); - dbus_message_iter_get_basic(&dict_entry_iter, &key); - dbus_message_iter_next(&dict_entry_iter); - dbus_message_iter_recurse(&dict_entry_iter, &variant_iter); - value_type = dbus_message_iter_get_signature(&variant_iter); - if (value_type[0] != 0 && value_type[1] == 0) { - switch (*value_type) { - case DBUS_TYPE_BOOLEAN: - if (strcmp(key, "Modified Status") == 0) { - dbus_message_iter_get_basic(&variant_iter, &value_bool); - properties.modified_status = value_bool; - } - break; - case DBUS_TYPE_STRING: - if (strcmp(key, "Description") == 0) { - dbus_message_iter_get_basic(&variant_iter, &value_string); - properties.description = value_string; - } else if (strcmp(key, "Notes") == 0) { - dbus_message_iter_get_basic(&variant_iter, &value_string); - properties.notes = value_string; - } - break; - } - } - } - -unref: - dbus_message_unref(reply_ptr); -} - -void LashProxy::project_set_description(const string& project_name, const string& description) { DBusMessage* reply_ptr; diff --git a/src/LashProxy.hpp b/src/LashProxy.hpp index 70583e6..5958289 100644 --- a/src/LashProxy.hpp +++ b/src/LashProxy.hpp @@ -28,15 +28,10 @@ struct ProjectInfo { std::string description; }; -struct LoadedProjectProperties { - bool modified_status; - std::string description; - std::string notes; -}; - class Patchage; class Session; class LashProxyImpl; +class LoadedProjectProperties; class LashProxy { public: diff --git a/src/Project.cpp b/src/Project.cpp index 0c19b8e..2e99727 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -17,14 +17,12 @@ */ #include "Project.hpp" -#include "LashProxy.hpp" #include "Client.hpp" using namespace std; using boost::shared_ptr; struct ProjectImpl { - LashProxy* proxy; string name; string description; string notes; @@ -32,18 +30,12 @@ struct ProjectImpl { list< shared_ptr<Client> > clients; }; -Project::Project(LashProxy* proxy, const string& name) +Project::Project(const string& name, const LoadedProjectProperties& properties) { - LoadedProjectProperties properties; - - proxy->get_loaded_project_properties(name, properties); - - _impl = new ProjectImpl(); - _impl->proxy = proxy; - _impl->name = name; - - _impl->description = properties.description; - _impl->notes = properties.notes; + _impl = new ProjectImpl(); + _impl->name = name; + _impl->description = properties.description; + _impl->notes = properties.notes; _impl->modified_status = properties.modified_status; } @@ -146,27 +138,3 @@ Project::on_notes_changed(const string& notes) _signal_notes_changed.emit(); } -void -Project::do_rename(const string& name) -{ - if (_impl->name != name) { - _impl->proxy->project_rename(_impl->name, name); - } -} - -void -Project::do_change_description(const string& description) -{ - if (_impl->description != description) { - _impl->proxy->project_set_description(_impl->name, description); - } -} - -void -Project::do_change_notes(const string& notes) -{ - if (_impl->notes != notes) { - _impl->proxy->project_set_notes(_impl->name, notes); - } -} - diff --git a/src/Project.hpp b/src/Project.hpp index b31efa3..6b70a4e 100644 --- a/src/Project.hpp +++ b/src/Project.hpp @@ -25,13 +25,17 @@ #include <sigc++/signal.h> struct ProjectImpl; -class LashProxy; -class LashProxyImpl; class Client; +struct LoadedProjectProperties { + bool modified_status; + std::string description; + std::string notes; +}; + class Project { public: - Project(LashProxy* proxy, const std::string& name); + Project(const std::string& name, const LoadedProjectProperties& properties); ~Project(); @@ -45,10 +49,6 @@ public: const Clients& get_clients() const; bool get_modified_status() const; - void do_rename(const std::string& name); - void do_change_description(const std::string& description); - void do_change_notes(const std::string& notes); - sigc::signal<void> _signal_renamed; sigc::signal<void> _signal_modified_status_changed; sigc::signal<void> _signal_description_changed; @@ -57,9 +57,6 @@ public: sigc::signal< void, boost::shared_ptr<Client> > _signal_client_added; sigc::signal< void, boost::shared_ptr<Client> > _signal_client_removed; -private: - friend class LashProxyImpl; - void on_name_changed(const std::string& name); void on_modified_status_changed(bool modified_status); void on_description_changed(const std::string& description); @@ -67,6 +64,7 @@ private: void on_client_added(boost::shared_ptr<Client> client); void on_client_removed(const std::string& id); +private: ProjectImpl* _impl; }; diff --git a/src/ProjectList.cpp b/src/ProjectList.cpp index c209ff7..9a67606 100644 --- a/src/ProjectList.cpp +++ b/src/ProjectList.cpp @@ -185,7 +185,7 @@ ProjectListImpl::on_menu_popup_close_project(shared_ptr<Project> project) void ProjectListImpl::on_menu_popup_project_properties(shared_ptr<Project> project) { - ProjectPropertiesDialog dialog(_app->xml()); + ProjectPropertiesDialog dialog(_app->lash_proxy(), _app->xml()); dialog.run(project); } diff --git a/src/ProjectPropertiesDialog.cpp b/src/ProjectPropertiesDialog.cpp index ef52c3d..36f0a1f 100644 --- a/src/ProjectPropertiesDialog.cpp +++ b/src/ProjectPropertiesDialog.cpp @@ -18,6 +18,8 @@ #include <gtkmm.h> #include <libglademm/xml.h> + +#include "LashProxy.hpp" #include "Patchage.hpp" #include "Project.hpp" #include "ProjectPropertiesDialog.hpp" @@ -28,18 +30,19 @@ using namespace std; struct ProjectPropertiesDialogImpl { - ProjectPropertiesDialogImpl(Glib::RefPtr<Gnome::Glade::Xml> xml); + ProjectPropertiesDialogImpl(LashProxy* proxy, Glib::RefPtr<Gnome::Glade::Xml> xml); - Widget<Gtk::Dialog> _dialog; - Widget<Gtk::Entry> _name; - Widget<Gtk::Entry> _description; + LashProxy* _proxy; + Widget<Gtk::Dialog> _dialog; + Widget<Gtk::Entry> _name; + Widget<Gtk::Entry> _description; Widget<Gtk::TextView> _notes; }; -ProjectPropertiesDialog::ProjectPropertiesDialog(Glib::RefPtr<Gnome::Glade::Xml> xml) +ProjectPropertiesDialog::ProjectPropertiesDialog(LashProxy* proxy, Glib::RefPtr<Gnome::Glade::Xml> xml) { - _impl = new ProjectPropertiesDialogImpl(xml); + _impl = new ProjectPropertiesDialogImpl(proxy, xml); } @@ -64,17 +67,27 @@ ProjectPropertiesDialog::run(shared_ptr<Project> project) result = _impl->_dialog->run(); if (result == 2) { - project->do_change_description(_impl->_description->get_text()); - project->do_change_notes(buffer->get_text()); - project->do_rename(_impl->_name->get_text()); + const std::string& old_name = project->get_name(); + const std::string& desc = _impl->_description->get_text(); + const std::string& notes = buffer->get_text(); + const std::string& name = _impl->_name->get_text(); + if (project->get_description() != desc) + _impl->_proxy->project_set_description(old_name, _impl->_description->get_text()); + if (project->get_notes() != notes) + _impl->_proxy->project_set_notes(old_name, buffer->get_text()); + if (old_name != name) + _impl->_proxy->project_rename(old_name, buffer->get_text()); } _impl->_dialog->hide(); } -ProjectPropertiesDialogImpl::ProjectPropertiesDialogImpl(Glib::RefPtr<Gnome::Glade::Xml> xml) - : _dialog(xml, "project_properties_dialog") +ProjectPropertiesDialogImpl::ProjectPropertiesDialogImpl( + LashProxy* proxy, + Glib::RefPtr<Gnome::Glade::Xml> xml) + : _proxy(proxy) + , _dialog(xml, "project_properties_dialog") , _name(xml, "project_name") , _description(xml, "project_description") , _notes(xml, "project_notes") diff --git a/src/ProjectPropertiesDialog.hpp b/src/ProjectPropertiesDialog.hpp index e20cc20..36e500e 100644 --- a/src/ProjectPropertiesDialog.hpp +++ b/src/ProjectPropertiesDialog.hpp @@ -26,7 +26,7 @@ class Project; class ProjectPropertiesDialog { public: - ProjectPropertiesDialog(Glib::RefPtr<Gnome::Glade::Xml> xml); + ProjectPropertiesDialog(LashProxy* proxy, Glib::RefPtr<Gnome::Glade::Xml> xml); ~ProjectPropertiesDialog(); void run(boost::shared_ptr<Project> project); |