[gnome-chess/chess-telepathy-networking-support-664946-rebase: 32/64] Add basic framework of gnome-chess-channel-handler application



commit dc433693214c669a9617ea234d00884effbe445e
Author: Chandni Verma <chandniverma2112 gmail com>
Date:   Fri Sep 7 06:06:55 2012 +0530

    Add basic framework of gnome-chess-channel-handler application

 data/Gnome.Chess.client                            |    7 +
 data/Makefile.am                                   |   18 ++-
 data/gnome-chess-network-window.ui                 |  219 ++++++++++++++++++++
 ...desktop.Telepathy.Client.Gnome.Chess.service.in |    3 +
 src/Makefile.am                                    |   29 +++
 src/gnome-chess-channel-handler.vala               |  206 ++++++++++++++++++
 src/gnome-chess.vala                               |   46 ++--
 7 files changed, 504 insertions(+), 24 deletions(-)
---
diff --git a/data/Gnome.Chess.client b/data/Gnome.Chess.client
new file mode 100644
index 0000000..09b4adc
--- /dev/null
+++ b/data/Gnome.Chess.client
@@ -0,0 +1,7 @@
+[org.freedesktop.Telepathy.Client]
+Interfaces=org.freedesktop.Telepathy.Client.Handler
+
+[org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 0]
+org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.DBusTube
+org.freedesktop.Telepathy.Channel.TargetHandleType u=1
+org.freedesktop.Telepathy.Channel.Type.DBusTube.ServiceName s=org.freedesktop.Telepathy.Client.Gnome.Chess
diff --git a/data/Makefile.am b/data/Makefile.am
index 2029567..79f7b1b 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -9,6 +9,7 @@ uidir = $(datadir)/gnome-chess
 ui_DATA = \
 	new-game-launcher.ui \
 	gnome-chess-game-window.ui \
+	gnome-chess-network-window.ui \
 	preferences.ui \
 	promotion-type-selector.ui
 
@@ -19,14 +20,29 @@ gsettings_SCHEMAS = org.gnome.gnome-chess.gschema.xml
 aidir = $(datadir)/gnome-chess/
 ai_DATA = engines.conf
 
+servicefiledir = $(datadir)/dbus-1/services
+servicefile_in_files = \
+	org.freedesktop.Telepathy.Client.Gnome.Chess.service.in
+servicefile_DATA = $(servicefile_in_files:.service.in=.service)
+
+org.freedesktop.Telepathy.Client.Gnome.Chess.service: org.freedesktop.Telepathy.Client.Gnome.Chess.service.in
+	$(AM_V_GEN)sed -e "s|[ ]libexecdir[@]|$(libexecdir)|" $< > $@
+
+clientfiledir = $(datarootdir)/telepathy/clients
+clientfile_DATA = \
+	Gnome.Chess.client
+
+
 man_MANS = gnome-chess.6
 
 EXTRA_DIST = engines.conf \
 	     org.gnome.gnome-chess.gschema.xml.in \
+       $(clientfile_DATA) \
+       $(servicefile_in_files) \
 	     $(man_MANS) \
 	     $(ui_DATA)
 
 CLEANFILES = $(desktop_DATA) $(gsettings_SCHEMAS)
-DISTCLEANFILES = $(desktop_DATA) $(gsettings_SCHEMAS)
+DISTCLEANFILES = $(desktop_DATA) $(gsettings_SCHEMAS) $(servicefile_DATA)
 
 -include $(top_srcdir)/git.mk
diff --git a/data/gnome-chess-network-window.ui b/data/gnome-chess-network-window.ui
new file mode 100644
index 0000000..65747bc
--- /dev/null
+++ b/data/gnome-chess-network-window.ui
@@ -0,0 +1,219 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkWindow" id="window_networked_chess">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Chess</property>
+    <signal name="window-state-event" handler="network_window_window_state_event_cb" swapped="no"/>
+    <signal name="configure-event" handler="network_window_configure_event_cb" swapped="no"/>
+    <child>
+      <object class="GtkGrid" id="grid_main">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_right">2</property>
+        <property name="margin_top">2</property>
+        <property name="margin_bottom">2</property>
+        <child>
+          <object class="GtkGrid" id="grid_contacts_presence_and_channels">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkGrid" id="grid_monitor">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_left">4</property>
+                <property name="margin_right">4</property>
+                <property name="margin_top">4</property>
+                <property name="margin_bottom">4</property>
+                <property name="hexpand">True</property>
+                <property name="row_spacing">4</property>
+                <property name="column_homogeneous">True</property>
+                <child>
+                  <object class="GtkComboBox" id="combobox_presence">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">3</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_goa">
+                    <property name="use_action_appearance">False</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <child>
+                      <object class="GtkImage" id="image_goa">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">goa</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">3</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_channels">
+                    <property name="use_action_appearance">False</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <child>
+                      <object class="GtkImage" id="image_glchess">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">glchess</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">2</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_contacts">
+                    <property name="use_action_appearance">False</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <child>
+                      <object class="GtkImage" id="image_user">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">user</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">2</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="contacts_box">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkScrolledWindow" id="scrolledwindow_list">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="margin_left">4</property>
+                    <property name="hexpand">True</property>
+                    <property name="vexpand">True</property>
+                    <property name="shadow_type">in</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkPaned" id="paned_game">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <child>
+              <object class="GtkFrame" id="frame_play">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">in</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment_play">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="left_padding">6</property>
+                    <property name="right_padding">6</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="resize">False</property>
+                <property name="shrink">True</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/data/org.freedesktop.Telepathy.Client.Gnome.Chess.service.in b/data/org.freedesktop.Telepathy.Client.Gnome.Chess.service.in
new file mode 100644
index 0000000..4ae6508
--- /dev/null
+++ b/data/org.freedesktop.Telepathy.Client.Gnome.Chess.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.freedesktop.Telepathy.Client.Gnome.Chess
+Exec= libexecdir@/games-channel-handler
diff --git a/src/Makefile.am b/src/Makefile.am
index f6d6172..be30bd8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,5 @@
 bin_PROGRAMS = gnome-chess
+libexec_PROGRAMS = gnome-chess-channel-handler
 
 noinst_PROGRAMS = test-chess-game test-chess-pgn
 
@@ -26,6 +27,29 @@ gnome_chess_SOURCES = \
 	chess-view-3d.vala \
 	history.vala
 
+gnome_chess_channel_handler_SOURCES = \
+	config.vapi \
+	gl.vapi \
+	glu.vapi \
+	glx.vapi \
+	3ds.vala \
+	gnome-chess.vala \
+	chess-launcher.vala \
+	gnome-chess-channel-handler.vala \
+	ai-profile.vala \
+	chess-bitboard.vala \
+	chess-clock.vala \
+	chess-engine.vala \
+	chess-engine-cecp.vala \
+	chess-engine-uci.vala \
+	chess-game.vala \
+	chess-pgn.vala \
+	chess-scene.vala \
+	chess-view.vala \
+	chess-view-2d.vala \
+	chess-view-3d.vala \
+	history.vala
+
 test_chess_game_SOURCES = \
 	chess-bitboard.vala \
 	chess-clock.vala \
@@ -79,6 +103,11 @@ gnome_chess_VALAFLAGS += \
 	--pkg GamesContacts-1.0
 endif
 
+gnome_chess_channel_handler_CFLAGS = $(gnome_chess_CFLAGS)
+gnome_chess_channel_handler_LDADD = $(gnome_chess_LDADD)
+gnome_chess_channel_handler_VALAFLAGS = $(gnome_chess_VALAFLAGS)
+
+
 CLEANFILES = \
 	$(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \
 	*_vala.stamp
diff --git a/src/gnome-chess-channel-handler.vala b/src/gnome-chess-channel-handler.vala
new file mode 100644
index 0000000..15b2755
--- /dev/null
+++ b/src/gnome-chess-channel-handler.vala
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2012 Chandni Verma
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ *
+ * Author: Chandni Verma <chandniverma2112 gmail com>
+ */
+
+public class HandlerApplication : Application
+{
+    private Gtk.Builder builder;
+
+    /* Objects from gnome-chess-network-window.ui */
+    private Gtk.Window? handler_window = null;
+    private Gtk.Widget grid_main;
+
+    private Gtk.Widget combobox_presence;
+    private Gtk.Widget button_goa;
+    private Gtk.Widget button_channels;
+    private Gtk.Widget button_contacts;
+    private Gtk.Container scrolledwindow_list;
+    private Gtk.Widget alignment_play;
+
+    private Gtk.Widget contacts_box;
+    private GamesContacts.IndividualStore? individual_store = null;
+    private GamesContacts.IndividualManager? individual_manager = null;
+    private GamesContacts.IndividualView? individual_view = null;
+    private GamesContacts.LiveSearch? search_widget;
+
+    /* Objects from gnome-chess-game-window.ui */
+    private Gtk.Widget view_box;
+    private Gtk.Widget handler_menubar;
+
+    public HandlerApplication ()
+    {
+        Object (
+            application_id: TelepathyGLib.CLIENT_BUS_NAME_BASE + "Gnome.Chess",
+            flags: ApplicationFlags.FLAGS_NONE);
+
+        settings = new Settings ("org.gnome.gnome-chess.Settings");
+
+        builder = new Gtk.Builder ();
+        try
+        {
+            builder.add_from_file (Path.build_filename (Config.PKGDATADIR,
+                "gnome-chess-network-window.ui", null));
+        }
+        catch (Error e)
+        {
+            warning ("Could not load UI: %s", e.message);
+        }
+
+        settings.changed.connect (settings_changed_cb);
+
+        create_handler_window ();
+        /* Associate the window to this application */
+        handler_window.application = this;
+
+        handler_window.show_all ();
+    }
+
+    private void create_handler_window ()
+    {
+        string [] objects_from_traditional_window =
+          {
+            "window_game_screen",
+            "undo_move_image",
+            "warning_image",
+            "help_image"
+          };
+        handler_window = (Gtk.Window) builder.get_object
+            ("window_networked_chess");
+        handler_window.delete_event.connect (handler_window.hide_on_delete);
+
+        grid_main = (Gtk.Widget) builder.get_object ("grid_main");
+        combobox_presence = (Gtk.Widget) builder.get_object
+            ("combobox_presence");
+        button_goa = (Gtk.Widget) builder.get_object ("button_goa");
+        button_channels = (Gtk.Widget) builder.get_object ("button_channels");
+        button_contacts = (Gtk.Widget) builder.get_object ("button_contacts");
+        scrolledwindow_list = (Gtk.Container) builder.get_object ("scrolledwindow_list");
+        contacts_box = (Gtk.Widget) builder.get_object ("contacts_box");
+        alignment_play = (Gtk.Widget) builder.get_object ("alignment_play");
+
+
+        /* Add objects from gnome-chess-game-window.ui */
+        try {
+            builder.add_objects_from_file (Path.build_filename (Config.PKGDATADIR,
+              "gnome-chess-game-window.ui", null),
+              objects_from_traditional_window);
+
+            view_box = (Gtk.Widget) builder.get_object ("view_box");
+            handler_menubar = (Gtk.Widget) builder.get_object ("menubar");
+
+            handler_menubar.unparent ();
+            (grid_main as Gtk.Grid).attach (handler_menubar, 0, 0, 2, 1);
+
+            view_box.reparent (alignment_play);
+
+            grid_main.show_all ();
+        }
+        catch (Error e)
+        {
+            warning ("Could not load UI: %s", e.message);
+        }
+
+        /* Connect signals of all objects to their respective handlers */
+        builder.connect_signals (this);
+
+        handler_window.title = _("Chess");
+
+        prepare_contact_list ();
+    }
+
+    private void prepare_contact_list ()
+    {
+        individual_manager =
+            GamesContacts.IndividualManager.dup_singleton ();
+        individual_store = new GamesContacts.IndividualStoreManager (
+            individual_manager);
+        individual_view = new GamesContacts.IndividualView (
+            individual_store,
+            GamesContacts.IndividualViewFeatureFlags.GROUPS_SAVE);
+
+        /* Create searching capability for the treeview */
+        search_widget = new GamesContacts.LiveSearch (
+            individual_view as Gtk.Widget);
+        individual_view.set_live_search (search_widget);
+
+        /* Add filter for contacts capable of playing chess */
+        individual_view.set_custom_filter ((model, iter, data)=>{
+              return (data as GamesContacts.IndividualView).filter_default (
+                  model, iter, GamesContacts.ActionType.PLAY_GLCHESS);
+            });
+
+        /* Evaluate contacts' presence using filter */
+        individual_view.refilter ();
+
+        /* Add to scrolled window and show */
+        scrolledwindow_list.add (individual_view);
+        scrolledwindow_list.show ();
+        individual_view.show ();
+
+        (contacts_box as Gtk.Container).add (search_widget);
+    }
+
+    [CCode (cname = "G_MODULE_EXPORT quit_cb", instance_pos = -1)]
+    private new void quit_cb (Gtk.Widget widget)
+    {
+        quit_game ();
+    }
+
+    /* Quits the application */
+    public new void quit_game ()
+    {
+        settings.sync ();
+    }
+
+    public override void activate ()
+    {
+      /* Handler window has been created by constructor already. Show it. */
+      handler_window.show_all ();
+      handler_window.present ();
+    }
+
+    [CCode (cname = "G_MODULE_EXPORT new_game_cb", instance_pos = -1)]
+    private new void new_game_cb (Gtk.Widget widget)
+    {
+    }
+
+}
+
+class GlChessChannelHandler
+{
+    private static int main (string[] args)
+    {
+        Intl.setlocale (LocaleCategory.ALL, "");
+        Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
+        Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+        Intl.textdomain (Config.GETTEXT_PACKAGE);
+
+        Gtk.init (ref args);
+
+        Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
+        icon_theme.append_search_path ("%s%s%s".printf
+            (Config.PKGDATADIR, Path.DIR_SEPARATOR_S, "icons"));
+
+        HandlerApplication app = new HandlerApplication ();
+        var result = app.run ();
+
+        return result;
+    }
+}
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 88e2bc2..e566e6c 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -3,55 +3,55 @@ extern void gtk_file_filter_set_name (Gtk.FileFilter filter, string name);
 
 public class Application : Gtk.Application
 {
-    private Settings settings;
+    protected Settings settings;
     private History history;
     private Gtk.Builder builder;
-    private Gtk.Builder preferences_builder;
+    protected Gtk.Builder preferences_builder;
     private ChessLauncher? launcher = null;
     private Gtk.Window? window = null;
 
     /* Chess game screen widgets */
-    private Gtk.Widget game_vbox;
+    protected Gtk.Widget game_vbox;
     private Gtk.Widget save_menu;
     private Gtk.Widget save_as_menu;
-    private Gtk.MenuItem fullscreen_menu;
-    private Gtk.InfoBar info_bar;
-    private Gtk.Label info_title_label;
-    private Gtk.Label info_label;
-    private Gtk.Container view_container;
-    private ChessScene scene;
-    private ChessView view;
+    protected Gtk.MenuItem fullscreen_menu;
+    protected Gtk.InfoBar info_bar;
+    protected Gtk.Label info_title_label;
+    protected Gtk.Label info_label;
+    protected Gtk.Container view_container;
+    protected ChessScene scene;
+    protected ChessView view;
     private Gtk.Widget undo_menu;
     private Gtk.Widget undo_button;
-    private Gtk.Widget resign_menu;
+    protected Gtk.Widget resign_menu;
     private Gtk.Widget resign_button;
-    private Gtk.Widget first_move_button;
-    private Gtk.Widget prev_move_button;
-    private Gtk.Widget next_move_button;
-    private Gtk.Widget last_move_button;
-    private Gtk.ComboBox history_combo;
-    private Gtk.Widget white_time_label;
-    private Gtk.Widget black_time_label;
-
-    private Gtk.Dialog? preferences_dialog = null;
+    protected Gtk.Widget first_move_button;
+    protected Gtk.Widget prev_move_button;
+    protected Gtk.Widget next_move_button;
+    protected Gtk.Widget last_move_button;
+    protected Gtk.ComboBox history_combo;
+    protected Gtk.Widget white_time_label;
+    protected Gtk.Widget black_time_label;
+
+    protected Gtk.Dialog? preferences_dialog = null;
     private Gtk.FileChooserDialog? open_dialog = null;
     private Gtk.InfoBar? open_dialog_info_bar = null;
     private Gtk.Label? open_dialog_error_label = null;
     private Gtk.FileChooserDialog? save_dialog = null;
     private Gtk.InfoBar? save_dialog_info_bar = null;
     private Gtk.Label? save_dialog_error_label = null;
-    private Gtk.AboutDialog? about_dialog = null;
+    protected Gtk.AboutDialog? about_dialog = null;
 
     private PGNGame pgn_game;
-    private ChessGame game;
+    protected ChessGame game;
     private bool in_history;
     private File game_file;
     private bool game_needs_saving;
     private string engines_file;
     private List<AIProfile> ai_profiles;
-    private ChessPlayer? opponent = null;
+    protected ChessPlayer? opponent = null;
     private ChessPlayer? human_player = null;
-    private ChessEngine? opponent_engine = null;
+    protected ChessEngine? opponent_engine = null;
 
     public Application (File? game_file)
     {



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