[ekiga] FriendOrFoe: Moved Foes edition where it belongs.



commit dd57e3f9222fcff9e56d9a8ab93e70de3dab77be
Author: Damien Sandras <dsandras seconix com>
Date:   Sun Oct 11 18:30:29 2015 +0200

    FriendOrFoe: Moved Foes edition where it belongs.
    
    The Preferences window should not have to deal with Engine specific
    components. Foe's edition should be done through Actions.
    
    The relevant actions have been moved to the main application menu.

 lib/engine/components/foe-list/foe-list.cpp        |   48 ++++++++++++---
 lib/engine/components/foe-list/foe-list.h          |    5 ++
 lib/engine/friend-or-foe/friend-or-foe.cpp         |    3 +-
 lib/engine/friend-or-foe/friend-or-foe.h           |    2 +-
 lib/engine/gui/gtk-frontend/call-window.cpp        |    8 +--
 lib/engine/gui/gtk-frontend/ekiga-app.cpp          |   12 ++++
 lib/engine/gui/gtk-frontend/preferences-window.cpp |   67 --------------------
 7 files changed, 61 insertions(+), 84 deletions(-)
---
diff --git a/lib/engine/components/foe-list/foe-list.cpp b/lib/engine/components/foe-list/foe-list.cpp
index 40e5b62..bc03a3a 100644
--- a/lib/engine/components/foe-list/foe-list.cpp
+++ b/lib/engine/components/foe-list/foe-list.cpp
@@ -37,11 +37,13 @@
 #include "ekiga-settings.h"
 
 #include "foe-list.h"
-#include <iostream>
+#include "form-request-simple.h"
 
-Ekiga::FoeList::FoeList(boost::shared_ptr<FriendOrFoe> fof):
-  friend_or_foe(fof)
+Ekiga::FoeList::FoeList(boost::shared_ptr<FriendOrFoe> fof)
 {
+  /* This Action can be added to the FriendOrFoe */
+  Ekiga::URIActionProvider::add_action (*fof, Ekiga::ActionPtr (new Ekiga::Action ("blacklist-edit", 
_("_Edit Blacklist"),
+                                                                                   boost::bind 
(&Ekiga::FoeList::edit_foes, this))));
 }
 
 
@@ -72,19 +74,49 @@ Ekiga::FoeList::add_foe (const std::string token)
   std::list<std::string> foes = settings->get_string_list ("foe-list");
   foes.push_back (token);
   settings->set_string_list ("foe-list", foes);
+}
+
+void
+Ekiga::FoeList::edit_foes ()
+{
+  boost::shared_ptr<Ekiga::FormRequestSimple> request =
+    boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind 
(&Ekiga::FoeList::on_edit_foes_form_submitted, this, _1, _2, _3)));
+
+  request->title (_("Edit the Blacklist"));
+
+  boost::scoped_ptr<Ekiga::Settings> settings(new Ekiga::Settings (CONTACTS_SCHEMA));
+  std::list<std::string> foes(settings->get_string_list ("foe-list"));
 
-  boost::shared_ptr<FriendOrFoe> fof = friend_or_foe.lock ();
-  if (fof)
-    remove_action (*fof, "blacklist");
+  request->editable_list ("foes",
+                          _("Blacklist"),
+                        std::list<std::string> (foes.begin (), foes.end ()),
+                        std::list<std::string>());
+
+  questions (request);
 }
 
+bool
+Ekiga::FoeList::on_edit_foes_form_submitted (bool submitted,
+                                             Ekiga::Form& result,
+                                             G_GNUC_UNUSED std::string& error)
+{
+  if (!submitted)
+    return false;
+
+  std::list<std::string> foes = result.editable_list ("foes");
+  boost::scoped_ptr<Ekiga::Settings> settings(new Ekiga::Settings (CONTACTS_SCHEMA));
+  settings->set_string_list ("foe-list", foes);
+
+  return true;
+}
 
 void
 Ekiga::FoeList::pull_actions (Actor & actor,
                               G_GNUC_UNUSED const std::string & display_name,
                               const std::string & uri)
 {
+  Ekiga::URIActionProvider::remove_action (actor, "blacklist-add");
   if (decide (std::string (), uri) != Ekiga::FriendOrFoe::Foe)
-    add_action (actor, Ekiga::ActionPtr (new Ekiga::Action ("blacklist", _("_Blacklist"),
-                                                            boost::bind (&Ekiga::FoeList::add_foe, this, 
uri))));
+    Ekiga::URIActionProvider::add_action (actor, Ekiga::ActionPtr (new Ekiga::Action ("blacklist-add", 
_("_Blacklist"),
+                                                                                      boost::bind 
(&Ekiga::FoeList::add_foe, this, uri))));
 }
diff --git a/lib/engine/components/foe-list/foe-list.h b/lib/engine/components/foe-list/foe-list.h
index d47abc5..55f9377 100644
--- a/lib/engine/components/foe-list/foe-list.h
+++ b/lib/engine/components/foe-list/foe-list.h
@@ -68,6 +68,11 @@ namespace Ekiga
     void add_foe (const std::string token);
 
   private:
+    void edit_foes ();
+    bool on_edit_foes_form_submitted (bool submitted,
+                                      Ekiga::Form& result,
+                                      G_GNUC_UNUSED std::string& error);
+
     /* ActionProvider api */
     void pull_actions (Actor & actor,
                        const std::string & display_name,
diff --git a/lib/engine/friend-or-foe/friend-or-foe.cpp b/lib/engine/friend-or-foe/friend-or-foe.cpp
index 0ae4aaa..4e559a0 100644
--- a/lib/engine/friend-or-foe/friend-or-foe.cpp
+++ b/lib/engine/friend-or-foe/friend-or-foe.cpp
@@ -41,8 +41,6 @@ Ekiga::FriendOrFoe::decide (const std::string domain,
   Identification answer = Unknown;
   Identification iter_answer;
 
-  remove_actions ();
-
   for (helpers_type::const_iterator iter = helpers.begin ();
        iter != helpers.end ();
        ++iter) {
@@ -60,4 +58,5 @@ void
 Ekiga::FriendOrFoe::add_helper (boost::shared_ptr<Ekiga::FriendOrFoe::Helper> helper)
 {
   helpers.push_front (helper);
+  helper->questions.connect (boost::ref (Ekiga::Actor::questions));
 }
diff --git a/lib/engine/friend-or-foe/friend-or-foe.h b/lib/engine/friend-or-foe/friend-or-foe.h
index 9054648..9bae07e 100644
--- a/lib/engine/friend-or-foe/friend-or-foe.h
+++ b/lib/engine/friend-or-foe/friend-or-foe.h
@@ -66,7 +66,7 @@ namespace Ekiga
     /* beware of the order : we prefer erring on the side of safety */
     typedef enum { Unknown, Foe, Neutral, Friend } Identification;
 
-    class Helper : public URIActionProvider
+    class Helper : public URIActionProvider, public Actor
     {
     friend class FriendOrFoe;
     public:
diff --git a/lib/engine/gui/gtk-frontend/call-window.cpp b/lib/engine/gui/gtk-frontend/call-window.cpp
index bf13be4..c5165bb 100644
--- a/lib/engine/gui/gtk-frontend/call-window.cpp
+++ b/lib/engine/gui/gtk-frontend/call-window.cpp
@@ -144,7 +144,6 @@ struct _EkigaCallWindowPrivate
   std::string received_audio_codec;
 
   Ekiga::GActorMenuPtr call_menu;
-  Ekiga::GActorMenuPtr fof_menu;
 
   Ekiga::scoped_connections connections;
   boost::shared_ptr<Ekiga::Settings> video_display_settings;
@@ -772,7 +771,6 @@ on_cleared_call_cb (boost::shared_ptr<Ekiga::Call> call,
     self->priv->destroy_timeout_id = 0;
     self->priv->timeout_id = 0;
     self->priv->bad_connection = false;
-    self->priv->fof_menu.reset ();
     self->priv->call_menu.reset ();
   }
 
@@ -791,7 +789,6 @@ static void on_missed_call_cb (boost::shared_ptr<Ekiga::Call> call,
     return; // Trying to clear another call than the current active one
   }
   self->priv->bad_connection = false;
-  self->priv->fof_menu.reset ();
   self->priv->call_menu.reset ();
 
   ekiga_call_window_update_calling_state (self, Standby);
@@ -1395,10 +1392,10 @@ ekiga_call_window_init_gui (EkigaCallWindow *self)
   g_object_unref (icon);
   gtk_button_set_image (GTK_BUTTON (button), image);
   gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
-  gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button), "win.blacklist");
+  gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (button), "win.blacklist-add");
   gtk_header_bar_pack_start (GTK_HEADER_BAR (self->priv->call_panel_toolbar), button);
   gtk_widget_set_tooltip_text (GTK_WIDGET (button),
-                               _("Add caller to the blacklist"));
+                               _("Add remote party to the blacklist"));
   gtk_widget_show (button);
 
   /* Devices settings */
@@ -1635,7 +1632,6 @@ call_window_add_call (GtkWidget *call_window,
 
   /* Update menu */
   self->priv->call_menu = Ekiga::GActorMenuPtr (new Ekiga::GActorMenu (*call));
-  self->priv->fof_menu = Ekiga::GActorMenuPtr (new Ekiga::GActorMenu (*self->priv->friend_or_foe));
 
   /* Update UI elements */
   CallingState s = call->is_outgoing () ? Calling : Called;
diff --git a/lib/engine/gui/gtk-frontend/ekiga-app.cpp b/lib/engine/gui/gtk-frontend/ekiga-app.cpp
index c019643..07e7b2e 100644
--- a/lib/engine/gui/gtk-frontend/ekiga-app.cpp
+++ b/lib/engine/gui/gtk-frontend/ekiga-app.cpp
@@ -111,6 +111,7 @@ struct _GmApplicationPrivate
 #endif
 
   Ekiga::GActorMenuStore banks_menu;
+  Ekiga::GActorMenuPtr fof_menu;
   unsigned int banks_actions_count;
 
   Ekiga::scoped_connections conns;
@@ -400,6 +401,11 @@ ekiga_main (int argc,
 
     boost::shared_ptr<Ekiga::AccountCore> account_core = app->priv->core.get<Ekiga::AccountCore> 
("account-core");
     app->priv->conns.add (account_core->questions.connect (boost::bind (&on_handle_questions_cb, _1, app)));
+
+    boost::shared_ptr<Ekiga::FriendOrFoe> friend_or_foe = app->priv->core.get<Ekiga::FriendOrFoe> 
("friend-or-foe");
+    app->priv->conns.add (friend_or_foe->questions.connect (boost::bind (&on_handle_questions_cb, _1, app)));
+    // Persistent FriendOrFoe menu
+    app->priv->fof_menu = Ekiga::GActorMenuPtr (new Ekiga::GActorMenu (*friend_or_foe));
   }
 
   /* Create the main application window */
@@ -494,6 +500,12 @@ gm_application_startup (GApplication *app)
                                "    </section>"
                                "    <section>"
                                "      <item>"
+                               "        <attribute name=\"label\" translatable=\"yes\">Edit 
_Blacklist</attribute>"
+                               "        <attribute name=\"action\">app.blacklist-edit</attribute>"
+                               "      </item>"
+                               "    </section>"
+                               "    <section>"
+                               "      <item>"
                                "        <attribute name=\"label\" translatable=\"yes\">Address 
_Book</attribute>"
                                "        <attribute name=\"action\">app.addressbook</attribute>"
                                "      </item>"
diff --git a/lib/engine/gui/gtk-frontend/preferences-window.cpp 
b/lib/engine/gui/gtk-frontend/preferences-window.cpp
index c81acf6..a6de8cb 100644
--- a/lib/engine/gui/gtk-frontend/preferences-window.cpp
+++ b/lib/engine/gui/gtk-frontend/preferences-window.cpp
@@ -448,25 +448,6 @@ static void sound_event_setting_changed (GSettings *,
                                          gpointer data);
 
 
-/* DESCRIPTION : This callback is triggered when the user asks to edit
- *               the blacklist
- * BEHAVIOR    : Display a form to edit the blacklist
- * PRE         : A pointer to the preferences window
- */
-static void edit_blacklist_cb (GtkWidget* widget,
-                              gpointer data);
-
-
-/* DESCRIPTION : This callback is triggered when the user submits the
- *               blacklist-editing form
- * BEHAVIOR    : /
- * PRE         : A pointer to the preferences window
- */
-static bool on_edit_blacklist_form_submitted (bool submitted,
-                                             Ekiga::Form& result,
-                                              std::string& error);
-
-
 /* Implementation */
 static void
 gm_prefs_window_sound_events_list_build (PreferencesWindow *self)
@@ -592,17 +573,6 @@ gm_pw_init_general_page (PreferencesWindow *self,
                   self->priv->protocols_settings, "rtp-tos-field",
                   _("The Type of Service (TOS) byte on outgoing RTP IP packets. This byte is used by the 
network to provide some level of Quality of Service (QoS). Default value 184 (0xB8) corresponds to Expedited 
Forwarding (EF) PHB as defined in RFC 3246."),
                   0.0, 255.0, 1.0);
-
-  /* Blacklist Settings */
-  gm_pw_subsection_new (container, _("Blacklist"));
-  GtkWidget* edit_blacklist_button = gtk_button_new_with_label(_("Edit"));
-  g_signal_connect (edit_blacklist_button, "clicked",
-                   G_CALLBACK (edit_blacklist_cb), (gpointer)self);
-  int pos = 0;
-  GTK_GRID_LAST_ROW (container, pos);
-  gtk_widget_set_halign (edit_blacklist_button, GTK_ALIGN_START);
-  gtk_container_set_border_width (GTK_CONTAINER (edit_blacklist_button), 0);
-  gtk_grid_attach (GTK_GRID (container), edit_blacklist_button, 0, pos-1, 2, 1);
 }
 
 static void
@@ -1636,43 +1606,6 @@ sound_event_toggled_cb (G_GNUC_UNUSED GtkCellRendererToggle *cell,
   gtk_tree_path_free (path);
 }
 
-static void
-edit_blacklist_cb (GtkWidget* /*widget*/,
-                  gpointer data)
-{
-  g_return_if_fail (data != NULL);
-
-  boost::shared_ptr<Ekiga::FormRequestSimple> request (new Ekiga::FormRequestSimple 
(&on_edit_blacklist_form_submitted));
-
-  request->title (_("Edit the Blacklist"));
-
-  boost::scoped_ptr<Ekiga::Settings> settings(new Ekiga::Settings (CONTACTS_SCHEMA));
-  std::list<std::string> foes(settings->get_string_list ("foe-list"));
-
-  request->editable_list ("foes", _("Current list of undesirables"),
-                        std::list<std::string> (foes.begin (), foes.end ()),
-                        std::list<std::string>());
-
-  FormDialog dialog(request, GTK_WIDGET (data));
-
-  dialog.run ();
-}
-
-static bool
-on_edit_blacklist_form_submitted (bool submitted,
-                                 Ekiga::Form& result,
-                                  G_GNUC_UNUSED std::string& error)
-{
-  if (!submitted)
-    return false;
-
-  std::list<std::string> foes = result.editable_list ("foes");
-  boost::scoped_ptr<Ekiga::Settings> settings(new Ekiga::Settings (CONTACTS_SCHEMA));
-  settings->set_string_list ("foe-list", foes);
-
-  return true;
-}
-
 
 void on_videoinput_device_added_cb (const Ekiga::VideoInputDevice & device,
                                     PreferencesWindow *self)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]