import gobject
import getopt
import sys
+import dbus
+import dbus.service
from Hage1 import thread_window
from Hage1 import board_window
-from Hage1 import brdlist_window
-from Hage1 import brdlist
from Hage1 import config
+from Hage1 import dbus_object
+from Hage1 import uri_opener
+
APPNAME = 'Hage1'
APPVERSION = '0.1'
+# where are these values ?
+DBUS_NAME_FLAG_ALLOW_REPLACEMENT = 1
+DBUS_NAME_FLAG_REPLACE_EXISTING = 2
+DBUS_NAME_FLAG_DO_NOT_QUEUE = 4
+DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1
+DBUS_REQUEST_NAME_REPLY_IN_QUEUE = 2
+DBUS_REQUEST_NAME_REPLY_EXISTS = 3
+DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER = 4
+
+dbus_bus_name = "tk.tetteke.Hage1"
+dbus_object_path = "/tk/tetteke/Hage1"
+dbus_object.dbus_interface_name = "tk.tetteke.Hage1"
+
def usage():
- print """usage: hage1 [-s bbs | -b board | -t thread]
--s, --bbs bbs : bbs id
--b, --board board : board id, ignored if bbs is empty
--t, --thread thread : thread id, ignored if bbs and board is empty"""
+ print """usage: hage1 uri"""
def getoption():
- bbs = None
- board = None
- thread = None
-
try:
opts, args = getopt.getopt(
- sys.argv[1:], "hs:b:t:", ["help", "bbs=", "board=", "thread="])
+ sys.argv[1:], "h", ["help"])
except getopt.GetoptError, msg:
print msg
usage()
if option in ("-h", "--help"):
usage()
sys.exit()
- elif option in ("-s", "--bbs"):
- bbs = value
- elif option in ("-b", "--board"):
- board = value
- elif option in ("-t", "--thread"):
- thread = value
-
- return bbs, board, thread
+ return args
+
if __name__ == "__main__":
# get option
- bbs, board, thread = getoption()
-
- gnome.init(APPNAME, APPVERSION)
- gobject.threads_init()
- config.APPNAME = APPNAME
- # init brdlist after setting config.APPNAME
- brdlist.init()
-
- if not bbs:
- brdlist_window.open_brdlist("2ch")
- elif not board:
- brdlist_window.open_brdlist(bbs)
- elif not thread:
- board_window.open_board(bbs, board)
+ uris = getoption()
+
+ # check if an instance exists
+ session_bus = dbus.SessionBus()
+ dbus_proxy_object = session_bus.get_object(
+ "org.freedesktop.DBus", "/org/freedesktop/DBus")
+ dbus_iface = dbus.Interface(dbus_proxy_object, "org.freedesktop.DBus")
+ req_name_ret = dbus_iface.RequestName(
+ dbus_bus_name, DBUS_NAME_FLAG_DO_NOT_QUEUE)
+
+ if req_name_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER or \
+ req_name_ret == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
+ # the instance does not exist. start normally.
+
+ bus_name = dbus.service.BusName(dbus_bus_name, bus=session_bus)
+ obj = dbus_object.DBusHage1Object(bus_name, dbus_object_path)
+
+ gnome.init(APPNAME, APPVERSION)
+ gobject.threads_init()
+ config.APPNAME = APPNAME
+
+ # open some windows
+ if uris:
+ from Hage1.BbsType import bbs_type_judge_uri
+ from Hage1.BbsType import bbs_type_exception
+ for uri in uris:
+ try:
+ uri_opener.open_uri(uri)
+ except bbs_type_exception.BbsTypeError, msg:
+ print msg
+ gtk.main()
else:
- thread_window.open_thread(bbs, board, thread)
+ # the instance exists. send message and exit.
+
+ proxy_object = session_bus.get_object(dbus_bus_name, dbus_object_path)
+ iface = dbus.Interface(proxy_object, dbus_object.dbus_interface_name)
- gtk.main()
+ # open some windows
+ if uris:
+ from Hage1.BbsType import bbs_type_judge_uri
+ from Hage1.BbsType import bbs_type_exception
+ for uri in uris:
+ try:
+ iface.open_uri(uri)
+ except bbs_type_exception.BbsTypeError, msg:
+ print msg