[ontv] Separate DBus client from core



commit c8472db439cef44689c4460a7fe5f8c4878a19a5
Author: Olof Kindgren <olki src gnome org>
Date:   Sat Apr 17 19:48:27 2010 +0200

    Separate DBus client from core
    
    The new executable ontv-dbus can be used to send messages to a
    running OnTV instance. This also means that the previous command
    line options for updating listings, showing search dialog and
    toggling program window has been removed from the applet.

 bin/Makefile.am         |    1 +
 bin/ontv-dbus           |   64 +++++++++++++++++++++++++++++++++++++++++++++++
 data/Makefile.am        |    2 +-
 data/ontv.schemas.in.in |    4 +-
 ontv/applet.py          |    5 +--
 ontv/main.py            |   26 +++++--------------
 ontv/ontv_core.py       |    9 +-----
 7 files changed, 79 insertions(+), 32 deletions(-)
---
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 4c758be..888ce24 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -1,4 +1,5 @@
 libexec_SCRIPTS = ontv-applet
+bin_SCRIPTS = ontv-dbus
 
 ontv_in_file = ontv-applet.in
 
diff --git a/bin/ontv-dbus b/bin/ontv-dbus
new file mode 100644
index 0000000..e6b2225
--- /dev/null
+++ b/bin/ontv-dbus
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2010 Olof Kindgren <olki src gnome org>
+
+# This file is part of OnTV.
+
+# OnTV 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.
+
+# OnTV 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 OnTV; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+
+from dbus import SessionBus, Interface
+from optparse import OptionParser
+
+class OnTVDbus:
+    """Simple frontend for sending messages to running OnTV instance"""
+
+    def __init__(self):
+        parser = OptionParser()
+        parser.add_option("-u", "--update-listings",
+                          action="store_true",
+                          help="Update listings")
+        parser.add_option("-t", "--toggle-program-window",
+                          action="store_true",
+                          help="Toggle visibility of the program window")
+        parser.add_option("-s", "--search",
+                          action="store_true",
+                          help="Show search dialog")
+
+        (options, args) = parser.parse_args()
+
+        remote_object = self.__get_running_instance()
+        if remote_object:
+            if options.update_listings:
+                remote_object.UpdateListings()
+            if options.toggle_program_window:
+                remote_object.ToggleWindow()
+            if options.search:
+                remote_object.ShowSearch()
+        else:
+            print("Couldn't find a running OnTV instance")
+
+    def __get_running_instance(self):
+        session_bus = SessionBus()
+        dbus_object = session_bus.get_object('org.freedesktop.DBus',
+                                     '/org/freedesktop/DBus')
+        dbus_iface = Interface(dbus_object, 'org.freedesktop.DBus')
+        services = dbus_iface.ListNames()
+        if "org.gnome.OnTV" in services:
+            return session_bus.get_object("org.gnome.OnTV","/DBusService")
+        return False
+
+if __name__ == "__main__":
+    ontv_dbus = OnTVDbus()
diff --git a/data/Makefile.am b/data/Makefile.am
index 4e3df0f..def2fd1 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -25,7 +25,7 @@ uidir   = $(datadir)/gnome-2.0/ui
 ui_DATA = GNOME_OnTVApplet.xml
 
 $(schema_in_files): $(schema_in_files:.schemas.in=.schemas.in.in)
-	sed -e "s|\ LIBEXECDIR\@|$(libexecdir)|" < $< > $@
+	sed -e "s|\ BINDIR\@|$(bindir)|" < $< > $@
 
 
 schemadir       = $(GCONF_SCHEMA_FILE_DIR)
diff --git a/data/ontv.schemas.in.in b/data/ontv.schemas.in.in
index fdd7c58..742133c 100644
--- a/data/ontv.schemas.in.in
+++ b/data/ontv.schemas.in.in
@@ -38,7 +38,7 @@
             <applyto>/desktop/gnome/keybindings/toggle_window_hotkey/action</applyto>
             <owner>ontv</owner>
             <type>string</type>
-            <default>@LIBEXECDIR@/ontv -wt</default>
+            <default>@BINDIR@/ontv-dbus -t</default>
             <locale name="C">
                 <short>Toggle program window action</short>
                 <long>Command for toggling visibility of the OnTV program window.</long>
@@ -71,7 +71,7 @@
             <applyto>/desktop/gnome/keybindings/show_search_program_hotkey/action</applyto>
             <owner>ontv</owner>
             <type>string</type>
-            <default>@LIBEXECDIR@/ontv -ws</default>
+            <default>@BINDIR@/ontv-dbus -s</default>
             <locale name="C">
                 <short>Show search program action</short>
                 <long>Command for showing the search program window.</long>
diff --git a/ontv/applet.py b/ontv/applet.py
index f8aefd1..d7766d6 100644
--- a/ontv/applet.py
+++ b/ontv/applet.py
@@ -43,9 +43,8 @@ class OnTVApplet(object):
         self.applet     = args[0]
         configure       = args[1]
         debug           = args[2]
-        message         = args[3]
 
-        self.ontv_core = OnTVCore(configure, debug, message, self.cb_status)
+        self.ontv_core = OnTVCore(configure, debug, self.cb_status)
 
         self.applet.set_applet_flags(gnomeapplet.EXPAND_MINOR)
 
@@ -72,7 +71,6 @@ class OnTVApplet(object):
         self.applet.connect("change-background", self.__change_background)
 
         self.applet.show_all()
-        self.ontv_core.set_program_window_position(self.get_docking_data())
 
     def __update_listings(self, uicomponent=None, verb=None):
         self.ontv_core.update_listings()
@@ -88,6 +86,7 @@ class OnTVApplet(object):
 
     def run(self):
         self.ontv_core.run()
+        self.ontv_core.set_program_window_position(self.get_docking_data())
 
     def __button_press(self, button, event):
         if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
diff --git a/ontv/main.py b/ontv/main.py
index ade33c3..7fe6bb6 100644
--- a/ontv/main.py
+++ b/ontv/main.py
@@ -45,15 +45,12 @@ def main():
         opts, args = getopt.getopt(sys.argv[1:], "cdhstuw", ["configure",
                                                              "debug",
                                                              "help",
-                                                             "search",
-                                                             "toggle",
-                                                             "update",
                                                              "window"])
     except getopt.GetoptError:
         opts = []
         args = sys.argv[1:]
 
-    configure = debug = standalone = message = False
+    configure = debug = standalone = False
     for o, a in opts:
         if o in ("-c", "--configure"):
             configure = True
@@ -61,12 +58,6 @@ def main():
             debug = True
         elif o in ("-h", "--help"):
             print_usage()
-        elif o in ("-s", "--search"):
-            message = "search"
-        elif o in ("-t", "--toggle"):
-            message = "toggle_pw"
-        elif o in ("-u", "--update"):
-            message = "update"
         elif o in ("-w", "--window"):
             standalone = True
 
@@ -82,12 +73,12 @@ def main():
                                                              48]))
         window.connect("destroy", gtk.main_quit)
         applet = gnomeapplet.Applet()
-        applet_factory(applet, None, configure, debug, message)
+        applet_factory(applet, None, configure, debug)
         applet.reparent(window)
         window.show_all()
         gtk.main()
     else:
-        activate_factory(debug, message)
+        activate_factory(debug)
 
 def print_usage():
     print _("Usage: %s [OPTIONS]...") % (sys.argv[0])
@@ -96,21 +87,18 @@ def print_usage():
     print "  -c, --configure	%s" % (_("run XMLTV assistant on startup"))
     print "  -d, --debug		%s" % (_("enable debug messages"))
     print "  -h, --help		%s" % (_("show this help message and exit"))
-    print "  -s, --search	%s" % (_("brings up search dialog"))
-    print "  -t, --toggle	%s" % (_("toggles visibility of program window"))
-    print "  -u, --update	%s" % (_("update TV listings"))
     print "  -w, --window		%s" % (_("run OnTV in a standalone window (for testing purposes)"))
 
     sys.exit()
 
-def applet_factory(applet, iid=None, configure=False, debug=False, message=False):
-    ontvapplet = OnTVApplet(applet, configure, debug, message)
+def applet_factory(applet, iid=None, configure=False, debug=False):
+    ontvapplet = OnTVApplet(applet, configure, debug)
     ontvapplet.run()
     return True
 
-def activate_factory(configure=False, debug=False, message=False):
+def activate_factory(configure=False, debug=False):
     gnomeapplet.bonobo_factory("OAFIID:GNOME_OnTVApplet_Factory",
                                gnomeapplet.Applet.__gtype__, NAME, VERSION,
-                               applet_factory, (configure, debug, message,))
+                               applet_factory, (configure, debug, ))
 
 # vim: set sw=4 et sts=4 tw=79 fo+=l:
diff --git a/ontv/ontv_core.py b/ontv/ontv_core.py
index e547258..e1a0c81 100644
--- a/ontv/ontv_core.py
+++ b/ontv/ontv_core.py
@@ -39,7 +39,7 @@ from ontv import NAME, VERSION, UI_DIR, LOCALE_DIR
 class OnTVCore:
     """Entry point for OnTV backend"""
 
-    def __init__(self, configure, debug, message, cb_status):
+    def __init__(self, configure, debug, cb_status):
 
         self.configure = configure
         self.debug = debug
@@ -60,12 +60,7 @@ class OnTVCore:
         remote_object = self.__get_running_instance()
 
         if remote_object:
-            if message == "update":
-                remote_object.UpdateListings()
-            elif message == "toggle_pw":
-                remote_object.ToggleWindow()
-            elif message == "search":
-                remote_object.ShowSearch()
+            print "OnTV is already running"
             exit()
         else:
             DBusService(self)



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