#!/usr/bin/env python # Copyright (C) 2006 by Aiwota Programmer # aiwotaprog@tetteke.tk # # This program 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. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import pygtk pygtk.require('2.0') import gtk import gnome.ui 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 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""" def getoption(): bbs = None board = None thread = None try: opts, args = getopt.getopt( sys.argv[1:], "hs:b:t:", ["help", "bbs=", "board=", "thread="]) except getopt.GetoptError, msg: print msg usage() sys.exit(2) for option, value in opts: 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 if __name__ == "__main__": # get option bbs, board, thread = 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 # 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() 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)