OSDN Git Service

brdlist and brdlist window are scratched, and will be built again.
[fukui-no-namari/fukui-no-namari.git] / src / hage1
1 #!/usr/bin/env python
2
3 # Copyright (C) 2006 by Aiwota Programmer
4 # aiwotaprog@tetteke.tk
5 #
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.
10 #
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.
15 #
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
19
20 import pygtk
21 pygtk.require('2.0')
22 import gtk
23 import gnome.ui
24 import gobject
25 import getopt
26 import sys
27 import dbus
28 import dbus.service
29
30 from Hage1 import thread_window
31 from Hage1 import board_window
32 from Hage1 import config
33 from Hage1 import dbus_object
34
35 APPNAME = 'Hage1'
36 APPVERSION = '0.1'
37
38 # where are these values ?
39 DBUS_NAME_FLAG_ALLOW_REPLACEMENT = 1
40 DBUS_NAME_FLAG_REPLACE_EXISTING = 2
41 DBUS_NAME_FLAG_DO_NOT_QUEUE = 4
42 DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1
43 DBUS_REQUEST_NAME_REPLY_IN_QUEUE = 2
44 DBUS_REQUEST_NAME_REPLY_EXISTS = 3
45 DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER = 4
46
47 dbus_bus_name = "tk.tetteke.Hage1"
48 dbus_object_path = "/tk/tetteke/Hage1"
49 dbus_object.dbus_interface_name = "tk.tetteke.Hage1"
50
51 def usage():
52     print """usage: hage1 uri"""
53
54 def getoption():
55     try:
56         opts, args = getopt.getopt(
57             sys.argv[1:], "h", ["help"])
58     except getopt.GetoptError, msg:
59         print msg
60         usage()
61         sys.exit(2)
62     for option, value in opts:
63         if option in ("-h", "--help"):
64             usage()
65             sys.exit()
66     return args
67
68     
69 if __name__ == "__main__":
70
71     # get option
72     uris = getoption()
73
74     # check if an instance exists
75     session_bus = dbus.SessionBus()
76     dbus_proxy_object = session_bus.get_object(
77         "org.freedesktop.DBus", "/org/freedesktop/DBus")
78     dbus_iface = dbus.Interface(dbus_proxy_object, "org.freedesktop.DBus")
79     req_name_ret = dbus_iface.RequestName(
80         dbus_bus_name, DBUS_NAME_FLAG_DO_NOT_QUEUE)
81
82     if req_name_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER or \
83        req_name_ret == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
84         # the instance does not exist. start normally.
85
86         bus_name = dbus.service.BusName(dbus_bus_name, bus=session_bus)
87         obj = dbus_object.DBusHage1Object(bus_name, dbus_object_path)
88
89         gnome.init(APPNAME, APPVERSION)
90         gobject.threads_init()
91         config.APPNAME = APPNAME
92
93         # open some windows
94         if uris:
95             from Hage1.BbsType import bbs_type_judge_uri
96             from Hage1.BbsType import bbs_type_exception
97             for uri in uris:
98                 try:
99                     bbs_type = bbs_type_judge_uri.get_type(uri)
100                     if bbs_type.is_board():
101                         board_window.open_board(uri)
102                     thread_window.open_thread(uri)
103                 except bbs_type_exception.BbsTypeError, msg:
104                     print msg
105             gtk.main()
106     else:
107         # the instance exists. send message and exit.
108
109         proxy_object = session_bus.get_object(dbus_bus_name, dbus_object_path)
110         iface = dbus.Interface(proxy_object, dbus_object.dbus_interface_name)
111
112         # open some windows
113         if uris:
114             from Hage1.BbsType import bbs_type_judge_uri
115             from Hage1.BbsType import bbs_type_exception
116             for uri in uris:
117                 try:
118                     bbs_type = bbs_type_judge_uri.get_type(uri)
119                     if bbs_type.is_board():
120                         iface.open_board(uri)
121                     iface.open_thread(uri)
122                 except bbs_type_exception.BbsTypeError, msg:
123                     print msg