OSDN Git Service

Introduce uri opener.
[fukui-no-namari/fukui-no-namari.git] / src / hage1
index f016cb8..3c7a1ac 100755 (executable)
--- a/src/hage1
+++ b/src/hage1
@@ -29,10 +29,9 @@ 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'
@@ -51,19 +50,12 @@ 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()
@@ -72,19 +64,13 @@ def getoption():
         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()
+    uris = getoption()
 
     # check if an instance exists
     session_bus = dbus.SessionBus()
@@ -105,30 +91,28 @@ if __name__ == "__main__":
         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)
-        else:
-            thread_window.open_thread(bbs, board, thread)
-
-        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:
+                    uri_opener.open_uri(uri)
+                except bbs_type_exception.BbsTypeError, msg:
+                    print msg
+            gtk.main()
     else:
         # 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)
 
-        if not bbs:
-            iface.open_brdlist("2ch")
-        elif not board:
-            iface.open_brdlist(bbs)
-        elif not thread:
-            iface.open_board(bbs, board)
-        else:
-            iface.open_thread(bbs, board, thread)
+        # 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