Exemplo n.º 1
0
 def toggle_server(self):
     if not hasattr(self, 'bs'):
         self.bonjour_auth_user = self.central_widget.bonjour_users\
                                      .currentText()
         self.bs = Bonjour_server(self.bonjour_auth_user)
     if not self.bs.is_running():
         self.bs.listen()
Exemplo n.º 2
0
 def toggle_server(self):
     if not hasattr(self, 'bs'):
         self.bonjour_auth_user = self.central_widget.bonjour_users\
                                      .currentText()
         self.bs = Bonjour_server(self.bonjour_auth_user)
     if not self.bs.is_running():
         self.bs.listen()
Exemplo n.º 3
0
class Ui_MainWindow(QtCore.QObject):
    def __init__(self, app):
        QtCore.QObject.__init__(self)
        self.app = app
        self.friend_list = []
        self.bonjour_auth_user = ''
        self.bonjour_users = {}

    def setupUi(self, main_window):
        self.main_window = main_window
        self.main_window.setObjectName("MainWindow")
        self.main_window.resize(800, 400)
        icon = QtGui.QIcon('/usr/share/icons/hicolor/128x128/apps'
                           '/heysms.png')
        self.main_window.setWindowIcon(icon)

        self.central_widget = Central_widget(self)
        self.main_window.setCentralWidget(self.central_widget)
        self.main_window.conf_dialog = Config_dialog(self.main_window)
        # Load saved config
        config.init_profile()
        if config.useusb == QtCore.Qt.Checked:
            config.start_useusb()

        ### Menu
        self.menubar = MenuBar(self.main_window)
        self.main_window.setMenuBar(self.menubar)

        QtCore.QMetaObject.connectSlotsByName(self.main_window)

        # Signals
        QtCore.QObject.connect(self.central_widget.reload_bonjour_users_button,
                               QtCore.SIGNAL("pressed ()"),
                               self.central_widget.reload_contacts)
        QtCore.QObject.connect(
            self.central_widget.bonjour_users,
            QtCore.SIGNAL("currentIndexChanged "
                          "(const QString&)"), self.change_bonjour_user)

        QtCore.QObject.connect(self.menubar.preference,
                               QtCore.SIGNAL("triggered()"),
                               self.main_window.conf_dialog.exec_)

        QtCore.QObject.connect(self.menubar.add_friend,
                               QtCore.SIGNAL("triggered()"), self.add_friend)

        QtCore.QObject.connect(self.menubar.about,
                               QtCore.SIGNAL("triggered()"), self.show_about)
        ## Quit
        QtCore.QObject.connect(self.menubar.quit, QtCore.SIGNAL("triggered()"),
                               self.app.quit)

    def toggle_server(self):
        if not hasattr(self, 'bs'):
            self.bonjour_auth_user = self.central_widget.bonjour_users\
                                         .currentText()
            self.bs = Bonjour_server(self.bonjour_auth_user)
        if not self.bs.is_running():
            self.bs.listen()

    def change_bonjour_user(self, new_bonjour_user):
        if not hasattr(self, 'bs'):
            self.toggle_server()
        else:
            self.bs.set_auth(new_bonjour_user)
            self.bonjour_auth_user = new_bonjour_user
            self.scheduler.set_auth(new_bonjour_user)
            config.update_last_authorized_user(new_bonjour_user)

    def add_friend(self):
        friends_dialog = QtGui.QInputDialog(self.main_window)
        friends_dialog.setComboBoxEditable(0)
        db = bsddb.hashopen('/home/user/.osso-abook/db/addressbook.db', 'r')
        friend_list = {}
        old_friend_list = [f.fullname for f in self.scheduler.friend_list]
        q_friend_dict = {}
        for contact in db.values():
            #            logger.debug("Trying to find name and "
            #                         "cell number in: %s" % contact.split('\n'))
            reg = re.compile('FN:(.*?)\\r', re.S | re.M)
            numbers = re.findall("TEL;TYPE=.*?CELL.*?:(.[0-9]*)\r\n", contact)
            m = re.search(reg, contact)
            if m is None:
                logger.debug("No name in contact")
                continue
            elif not numbers:
                logger.debug("No cell phone found")
                continue

            name = m.group(1).decode('utf-8')
            for num in numbers:
                logger.debug("Found : %s - %s" % (name, num))
                if name in old_friend_list:
                    logger.debug("Friend already in list: %s" % name)
                    continue

                i = 1
                while name in friend_list:
                    name = name + " (%s)" % str(i)
                    i = i + 1

                # Prepare lists
                friend_list[num] = name
                q_friend_dict["%s - %s" % (name, num)] = num

        q_friend_list = QtCore.QStringList(sorted(q_friend_dict.keys()))
        friends_dialog.setComboBoxItems(q_friend_list)
        friends_dialog.setWindowTitle("Add a friend")
        friends_dialog.setLabelText("Select a friend")
        ret = friends_dialog.exec_()

        if ret == 0:
            logger.debug("Dialog not confirmed")
            return

        raw_name = str(friends_dialog.textValue())
        number = q_friend_dict[raw_name]
        select_friend = friend_list[number]
        bonjour_auth_username = str(self.bonjour_auth_user)
        auth_user = {
            bonjour_auth_username: self.bonjour_users[bonjour_auth_username]
        }

        # Check if friend is already in friend list
        if select_friend in old_friend_list:
            logger.debug("Selected friend already in list: %s" % select_friend)
            return

        new_friend = Friend(select_friend, number, auth_user)
        # Add to friend list in table model
        self.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"),
                                              new_friend)
        # append to scheduler friend list
        self.scheduler.friend_list.append(new_friend)
        # Register it on bonjour
        new_friend.start()

    def show_about(self):
        icon = QtGui.QIcon('/usr/share/icons/hicolor/48x48/hildon'
                           '/general_refresh.png')
        vars = {}
        vars['version'] = "1.6.9"
        message = QtCore.QString(
            """<center><h2>HeySms</h2></center>"""
            """<center>Version: %(version)s</center>"""
            """<br/>Visite web site: <a href="http://talk.maemo.org/showthread.php?t=84705">Here</a> """
            """<br/>Report bugs: <a href="https://github.com/titilambert/HeySms/issues?milestone=&page=1&state=open">Here</a> """
            """<br/>Thanks: """
            """<ul>"""
            """<li>My Doudoune</li>"""
            """<li>David Rodigari</li>"""
            """<li>Oskar Welzl</li>"""
            """<li>Stefan Siegl</li>"""
            """</ul>"""
            """ """ % vars)
        QtGui.QMessageBox.about(self.main_window, "About", message)
Exemplo n.º 4
0
class Ui_MainWindow(QtCore.QObject):
    def __init__(self, app, translator):
        QtCore.QObject.__init__(self)
        self.app = app
        self.friend_list = []
        self.bonjour_auth_user = ''
        self.bonjour_users = {}
        self.translator = translator

    def setupUi(self, main_window):
        self.main_window = main_window
        self.main_window.setObjectName("MainWindow")
        self.main_window.resize(800, 400)
        icon = QtGui.QIcon('/usr/share/icons/hicolor/128x128/apps'
                           '/heysms.png')
        self.main_window.setWindowIcon(icon)

        self.central_widget = Central_widget(self)
        self.main_window.setCentralWidget(self.central_widget)
        self.main_window.conf_dialog = Config_dialog(self.main_window)
        # Load saved config
        config.init_profile()
        if config.useusb == QtCore.Qt.Checked:
            config.start_useusb()

        ### Menu
        self.menubar = MenuBar(self.main_window)
        self.main_window.setMenuBar(self.menubar)

        QtCore.QMetaObject.connectSlotsByName(self.main_window)

        # Signals
        QtCore.QObject.connect(self.central_widget.reload_bonjour_users_button,
                               QtCore.SIGNAL("pressed ()"),
                               self.central_widget.reload_contacts)
        QtCore.QObject.connect(self.central_widget.bonjour_users,
                               QtCore.SIGNAL("currentIndexChanged "
                                             "(const QString&)"),
                               self.change_bonjour_user)

        QtCore.QObject.connect(self.menubar.preference,
                               QtCore.SIGNAL("triggered()"),
                               self.main_window.conf_dialog.exec_)

        QtCore.QObject.connect(self.menubar.add_friend,
                               QtCore.SIGNAL("triggered()"),
                               self.add_friend)

        QtCore.QObject.connect(self.menubar.about,
                               QtCore.SIGNAL("triggered()"),
                               self.show_about)
        ## Quit
        QtCore.QObject.connect(self.menubar.quit,
                               QtCore.SIGNAL("triggered()"),
                               self.app.quit)

    def toggle_server(self):
        if not hasattr(self, 'bs'):
            self.bonjour_auth_user = self.central_widget.bonjour_users\
                                         .currentText()
            self.bs = Bonjour_server(self.bonjour_auth_user)
        if not self.bs.is_running():
            self.bs.listen()

    def change_bonjour_user(self, new_bonjour_user):
        if not hasattr(self, 'bs'):
            self.toggle_server()
        else:
            self.bs.set_auth(new_bonjour_user)
            self.bonjour_auth_user = new_bonjour_user
            self.scheduler.set_auth(new_bonjour_user)
            config.update_last_authorized_user(new_bonjour_user)

    def add_friend(self):
        friends_dialog = QtGui.QInputDialog(self.main_window)
        friends_dialog.setComboBoxEditable(0)
        friends_dialog.setOkButtonText(self.tr("Done"))
        db = bsddb.hashopen('/home/user/.osso-abook/db/addressbook.db', 'r')
        friend_list = {}
        old_friend_list = [f.fullname for f in self.scheduler.friend_list]
        q_friend_dict = {}
        for contact in db.values():
#            logger.debug("Trying to find name and "
#                         "cell number in: %s" % contact.split('\n'))
            reg = re.compile('FN:(.*?)\\r', re.S|re.M)
            numbers = re.findall("TEL;TYPE=.*?CELL.*?:(.[0-9]*)\r\n", contact)
            m = re.search(reg, contact)
            if m is None:
                logger.debug("No name in contact")
                continue
            elif not numbers:
                logger.debug("No cell phone found")
                continue

            name = m.group(1).decode('utf-8')
            for num in numbers:
                logger.debug("Found : %s - %s" % (name, num))
                if name in old_friend_list:
                    logger.debug("Friend already in list: %s" % name)
                    continue

                i = 1
                while name in friend_list:
                    name = name + " (%s)" % str(i)
                    i = i + 1

                # Prepare lists
                friend_list[num] = name
                q_friend_dict["%s - %s" % (name, num)] = num

        q_friend_list = QtCore.QStringList(sorted(q_friend_dict.keys()))
        friends_dialog.setComboBoxItems(q_friend_list)
        friends_dialog.setWindowTitle(self.tr("Add a friend"))
        friends_dialog.setLabelText(self.tr("Select a friend"))
        ret = friends_dialog.exec_()

        if ret == 0:
            logger.debug("Dialog not confirmed")
            return

        raw_name = unicode(friends_dialog.textValue())
        number = q_friend_dict[raw_name]
        select_friend = friend_list[number]
        bonjour_auth_username = str(self.bonjour_auth_user)
        auth_user = {bonjour_auth_username:
                self.bonjour_users[bonjour_auth_username]}

        # Check if friend is already in friend list
        if select_friend in old_friend_list:
                logger.debug("Selected friend already in list: %s" % select_friend)
                return

        new_friend = Friend(select_friend, number, auth_user)
        # Add to friend list in table model
        self.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"), new_friend)
        # append to scheduler friend list
        self.scheduler.friend_list.append(new_friend)
        # Register it on bonjour
        new_friend.start()

    def show_about(self):
        icon = QtGui.QIcon('/usr/share/icons/hicolor/48x48/hildon'
                           '/general_refresh.png')
        vars = {}
        vars['version'] = "1.7.2"
        message = QtCore.QString(self.tr("""<center><h2>HeySms</h2></center>"""
                                 """<center>Version: %(version)s</center>"""
                                 """<br/>Visite web site: <a href="http://talk.maemo.org/showthread.php?t=84705">Here</a> """
                                 """<br/>Report bugs: <a href="https://github.com/titilambert/HeySms/issues?milestone=&page=1&state=open">Here</a> """
                                 """<br/>Thanks: """
                                 """<ul>"""
                                 """<li>My Doudoune</li>"""
                                 """<li>David Rodigari</li>"""
                                 """<li>Oskar Welzl</li>"""
                                 """<li>Stefan Siegl</li>"""
                                 """</ul>"""
                                 """ """ % vars))
        QtGui.QMessageBox.about(self.main_window, self.tr("About"), message)