3 # Copyright (C) 2006 by Aiwota Programmer
4 # aiwotaprog@tetteke.tk
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 from Hage1 import thread_window
31 from Hage1 import board_window
32 from Hage1 import config
33 from Hage1 import dbus_object
34 from Hage1 import uri_opener
35 from Hage1 import session
40 # where are these values ?
41 DBUS_NAME_FLAG_ALLOW_REPLACEMENT = 1
42 DBUS_NAME_FLAG_REPLACE_EXISTING = 2
43 DBUS_NAME_FLAG_DO_NOT_QUEUE = 4
44 DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1
45 DBUS_REQUEST_NAME_REPLY_IN_QUEUE = 2
46 DBUS_REQUEST_NAME_REPLY_EXISTS = 3
47 DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER = 4
49 dbus_bus_name = "tk.tetteke.Hage1"
50 dbus_object_path = "/tk/tetteke/Hage1"
51 dbus_object.dbus_interface_name = "tk.tetteke.Hage1"
54 print """usage: hage1 uri"""
58 opts, args = getopt.getopt(
59 sys.argv[1:], "h", ["help"])
60 except getopt.GetoptError, msg:
64 for option, value in opts:
65 if option in ("-h", "--help"):
71 if __name__ == "__main__":
76 # check if an instance exists
77 session_bus = dbus.SessionBus()
78 dbus_proxy_object = session_bus.get_object(
79 "org.freedesktop.DBus", "/org/freedesktop/DBus")
80 dbus_iface = dbus.Interface(dbus_proxy_object, "org.freedesktop.DBus")
81 req_name_ret = dbus_iface.RequestName(
82 dbus_bus_name, DBUS_NAME_FLAG_DO_NOT_QUEUE)
84 if req_name_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER or \
85 req_name_ret == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
86 # the instance does not exist. start normally.
88 bus_name = dbus.service.BusName(dbus_bus_name, bus=session_bus)
89 obj = dbus_object.DBusHage1Object(bus_name, dbus_object_path)
91 gnome.init(APPNAME, APPVERSION)
92 gobject.threads_init()
93 config.APPNAME = APPNAME
97 from Hage1.BbsType import bbs_type_judge_uri
98 from Hage1.BbsType import bbs_type_exception
101 uri_opener.open_uri(uri)
102 except bbs_type_exception.BbsTypeError, msg:
108 # the instance exists. send message and exit.
110 proxy_object = session_bus.get_object(dbus_bus_name, dbus_object_path)
111 iface = dbus.Interface(proxy_object, dbus_object.dbus_interface_name)
115 from Hage1.BbsType import bbs_type_judge_uri
116 from Hage1.BbsType import bbs_type_exception
120 except bbs_type_exception.BbsTypeError, msg: