Example #1
0
    def sendSMS(self, number, text, senderName):
        #Spedisco il messaggio: inizializzo il PreferenceManager
        #ed il CodingManager
        p = PreferenceManager.getInstance()
        cm = CodingManager.getInstance()

        masterKey = None
        if p.isEncryptionEnabled():
            keyValid = False
            while keyValid == False:
                masterKey = raw_input("Inserisci la Master Password:"******"Sito "+senderName+" non riconosciuto."
        else:
            reg = {}
            s = Sender.getPlugins()[senderName]
            if s.requiresRegistration:
                try:
                    for i in s.requiresRegistration:
                        reg[i] = p.getAccount(senderName, i, masterKey)
                except PreferenceManagerError:
                    for i in s.requiresRegistration:
                        p.addAccount(i, cm.unicodeStdin(
                            raw_input("Immetti il dato "+i+": ")),
                                     senderName, masterKey)
                    for i in s.requiresRegistration:
                        reg[i] = p.getAccount(senderName, i, masterKey)
            s.sendOne(number, text, reg)
            print "Spedito!"
Example #2
0
    def sendSMS(self, number, text, masterKey, senderName):
        #Spedisco il messaggio: inizializzo il PreferenceManager
        #ed il CodingManager
        p = PreferenceManager.getInstance()
        cm = CodingManager.getInstance()

        #Se necessario, cerco il nome in rubrica
        #Inizializzo il sender e mando il messaggio
        senderName = senderName.title()
        if number.isdigit() == False:
            number = p.lookup(number)
        if Sender.getPlugins().has_key(senderName) == False:
            print "Sito "+senderName+" non riconosciuto."
        else:
            reg = {}
            s = Sender.getPlugins()[senderName]
            if s.requiresRegistration:
                try:
                    for i in s.requiresRegistration:
                        reg[i] = p.getAccount(senderName, i, masterKey)
                except PreferenceManagerError:
                    for i in s.requiresRegistration:
                        p.addAccount(i, cm.unicodeStdin(
                            raw_input("Immetti il dato "+i+": ")),
                                     senderName, masterKey)
                    for i in s.requiresRegistration:
                        reg[i] = p.getAccount(senderName, i, masterKey)
            s.send(number, text, reg)
            print "Spedito!"
Example #3
0
    def sendSMS(self, number, text, masterKey, senderName):
        #Spedisco il messaggio: inizializzo il PreferenceManager
        #ed il CodingManager
        p = PreferenceManager.getInstance()
        cm = CodingManager.getInstance()

        #Se necessario, cerco il nome in rubrica
        #Inizializzo il sender e mando il messaggio
        senderName = senderName.title()
        if number.isdigit() == False:
            number = p.lookup(number)
        if Sender.getPlugins().has_key(senderName) == False:
            print "Sito " + senderName + " non riconosciuto."
        else:
            reg = {}
            s = Sender.getPlugins()[senderName]
            if s.requiresRegistration:
                try:
                    for i in s.requiresRegistration:
                        reg[i] = p.getAccount(senderName, i, masterKey)
                except PreferenceManagerError:
                    for i in s.requiresRegistration:
                        p.addAccount(
                            i,
                            cm.unicodeStdin(
                                raw_input("Immetti il dato " + i + ": ")),
                            senderName, masterKey)
                    for i in s.requiresRegistration:
                        reg[i] = p.getAccount(senderName, i, masterKey)
            s.send(number, text, reg)
            print "Spedito!"
Example #4
0
    def run(self):
        """Avvia questa interfaccia."""
        exitCode = 0
        try:
            p = PreferenceManager.getInstance()
            cm = CodingManager.getInstance()
            masterKey = None
            print "(Questo programma funziona anche dalla linea di comando, \
vedi LEGGIMI)"

            masterKey = None
            if p.isEncryptionEnabled():
                keyValid = False
                while keyValid == False:
                    masterKey = raw_input("Inserisci la Master Password:"******"Immetti il numero del destinatario e \
premi INVIO: ")
            number = cm.unicodeStdin(number)
            text = cm.unicodeStdin(
                raw_input("Immetti il testo e premi INVIO: "))
            print "Siti disponibili per l'invio:"
            plugins = Sender.getPlugins().keys()
            for i in plugins:
                print i
            print "Immetti il nome del sito. Le maiuscole non fanno differenza."
            sender = raw_input("Premi solo INVIO per " + plugins[0] + ":")
            sender = cm.unicodeStdin(sender)
            if (sender == ""):
                sender = plugins[0]
            proxy = ""
            if p.isProxyEnabled():
                print "Proxy attualmente configurato: " + p.getProxy()
                proxy = raw_input("(INVIO per confermare, \"no\" per " +
                                  "disabilitare o nuovo indirizzo:)")
                if proxy == "no":
                    p.unsetProxy()
                elif proxy != "":
                    p.setProxy(proxy)
            else:
                print "Immetti l'indirizzo e la porta del proxy:"
                proxy = raw_input(
                    "(se non sai cosa sono o non li usi premi INVIO)")
                if proxy != "":
                    p.setProxy(proxy)
            if p.isProxyEnabled() == True:
                os.environ["http_proxy"] = p.getProxy()
            self.sendSMS(number, text, masterKey, sender)
        except NotFoundError, e:
            print cm.encodeStdout(e.__str__())
            exitCode = 1
Example #5
0
    def run(self):
        """Avvia questa interfaccia."""
        exitCode = 0
        try:
            p = PreferenceManager.getInstance()
            cm = CodingManager.getInstance()
            masterKey = None
            print "(Questo programma funziona anche dalla linea di comando, \
vedi LEGGIMI)"
            masterKey = None
            if p.isEncryptionEnabled():
                keyValid = False
                while keyValid == False:
                    masterKey = raw_input("Inserisci la Master Password:"******"Immetti il numero del destinatario e \
premi INVIO: ")
            number = cm.unicodeStdin(number)
            text = cm.unicodeStdin(
                raw_input("Immetti il testo e premi INVIO: "))
            print "Siti disponibili per l'invio:"
            plugins = Sender.getPlugins().keys()
            for i in plugins:
                print i
            print "Immetti il nome del sito. Le maiuscole non fanno differenza."
            sender = raw_input("Premi solo INVIO per "+plugins[0]+":")
            sender = cm.unicodeStdin(sender)
            if (sender == ""):
                sender = plugins[0]
            proxy = ""
            if p.isProxyEnabled():
                print "Proxy attualmente configurato: " + p.getProxy()
                proxy = raw_input("(INVIO per confermare, \"no\" per " +
                    "disabilitare o nuovo indirizzo:)")
                if proxy == "no":
                    p.unsetProxy()
                elif proxy != "":
                    p.setProxy(proxy)
            else:
                print "Immetti l'indirizzo e la porta del proxy:"
                proxy = raw_input("(se non sai cosa sono o non li usi premi INVIO)")
                if proxy != "":
                    p.setProxy(proxy)
            if p.isProxyEnabled() == True:
                os.environ["http_proxy"] = p.getProxy()
            self.sendSMS(number, text, masterKey, sender)
        except NotFoundError, e:
            print cm.encodeStdout(e.__str__())
            exitCode = 1
Example #6
0
 def run(self):
     """Avvia questa interfaccia."""
     print "ermeSms by Thomas Bertani, https://github.com/sylarpowa/ermeSms\n"
     print "USO:"
     print "MODALITA' INTERATTIVA: MoioSMS\n"
     print "MODALITA' A LINEA DI COMANDO: "
     print "MoioSMS numero \"testo\" (invia un SMS a un numero)"
     print "MoioSMS nome \"testo\" (invia un SMS a un numero in rubrica)"
     print "MoioSMS -a nome numero (aggiunge un numero in rubrica)"
     print "MoioSMS -m (mostra la rubrica)\n"
     print "Per usare un sito in particolare, aggiungere uno dei parametri"
     print "seguenti:"
     for i in Sender.getPlugins():
         print i
     print "\nPer usare un proxy, aggiungere -p indirizzo:porta in coda"
     print "(usare -p no per disabilitare)"
     print "Address book, password and settings are into the file .ermesms/config.ini."
     print "Comments/Suggests/Bugs: [email protected]"
    def __init__(self, mf):
        QDialog.__init__(self, mf, mf.defaultFlag)
        self.senderList = Sender.getPlugins().keys()
        self.senderList.sort()
        self.messageLabel = QLabel("Scegli i sender che utilizzerai (OK se " + "non sei sicuro)")
        self.okButton = QPushButton("OK")
        self.boxes = {}
        for i in self.senderList:
            self.boxes[i] = QCheckBox(i)
            self.boxes[i].setChecked(True)

        self.__set_properties()
        self.__do_layout()

        self.connect(self.okButton, SIGNAL("clicked(bool)"), self.okButtonEventHandler)

        posx = (QDesktopWidget().width() - self.width()) / 2
        posy = ((QDesktopWidget().height() / 3 * 2) - self.height()) / 2
        self.move(posx, posy)
Example #8
0
    def __init__(self, mf):
        QDialog.__init__(self, mf, mf.defaultFlag)
        self.senderList = Sender.getPlugins().keys()
        self.senderList.sort()
        self.messageLabel = QLabel("Scegli i sender che utilizzerai (OK se " +
                                   "non sei sicuro)")
        self.okButton = QPushButton("OK")
        self.boxes = {}
        for i in self.senderList:
            self.boxes[i] = QCheckBox(i)
            self.boxes[i].setChecked(True)

        self.__set_properties()
        self.__do_layout()

        self.connect(self.okButton, SIGNAL('clicked(bool)'),
                     self.okButtonEventHandler)

        posx = (QDesktopWidget().width() - self.width()) / 2
        posy = ((QDesktopWidget().height() / 3 * 2) - self.height()) / 2
        self.move(posx, posy)
Example #9
0
 def stopButtonEventHandler(self):
     """Gestisce l'evento di interruzione di invio"""
     Sender.getPlugins()[self.getSender()].stop = True
Example #10
0
    def __init__(self):
        try:
            flag = Qt.WindowFlags(Qt.CustomizeWindowHint |
                                  Qt.WindowSystemMenuHint |
                                  Qt.WindowMinimizeButtonHint |
                                  Qt.WindowCloseButtonHint)
            self.defaultFlag = Qt.WindowFlags(Qt.CustomizeWindowHint |
                                              Qt.WindowTitleHint |
                                              Qt.WindowSystemMenuHint |
                                              Qt.WindowCloseButtonHint)
        except:
            flag = Qt.WindowFlags()
            self.defaultFlag = Qt.WindowFlags()

        QFrame.__init__(self, None , flag)
        self.setWindowState(Qt.WindowActive)

        #Icona della titlebar
        pixmap = QPixmap()
        pixmap.loadFromData(getIconData())
        icon = QIcon()
        icon.addPixmap(pixmap)
        self.setWindowIcon(icon)

        self.label = QLabel("A:")
        self.destinationComboBox = QComboBox()
        self.destinationComboBox.setInsertPolicy(QComboBox.NoInsert)
        self.destinationComboBox.setEditable(True)
        self.destinationComboBox.completer().setCaseSensitivity(
            Qt.CaseSensitive)
        self.fillContacts()
        self.deleteButton = QPushButton("Cancella")
        self.addButton = QPushButton("Metti in rubrica")
        self.label.setMinimumHeight(self.addButton.minimumSizeHint().height())

        self.messageTextCtrl = QTextEdit("Inserisci il tuo messaggio qui.")
        self.messageTextCtrl.setTabChangesFocus(True)
        self.messageTextCtrl.setMinimumHeight(70)
        if self.pm.isSenderListAvailable(Sender.getPlugins().keys()) == False:
            scd=SenderChoicesDialog(self)
            result = scd.exec_()
            if result == 0:
                senderList = Sender.getPlugins().keys()
            else:
                senderList = scd.getSenderList()
                self.pm.setSenderList(senderList,Sender.getPlugins().keys())
        else: senderList = self.pm.getSenderList()
        self.senderBoxes = {}
        self.senderRadioBox = QGroupBox("Scegli il sito per l'invio")
        for i in senderList:
            self.senderBoxes[i] = QRadioButton(i)
        self.senderBoxes[senderList[0]].setChecked(True)
        self.logButton = QPushButton("Apri Registro")
        self.sentLabel = QLabel("Inviati: 0")
        self.check = QCheckBox("Posticipa invio")
        self.sendButton = QPushButton("Invia!")
        self.stopButton = QPushButton("FERMA!")
        self.messageLabel = QLabel("Non in rubrica")
        self.gauge = QProgressBar()
        self.gauge.setRange(0,1000)
        self.gauge.setMinimumHeight(32)
        self.normalcursor = self.cursor()
        self.waitcursor = QCursor(Qt.BusyCursor)

        self.bitmap = QLabel()
        self.iconsize = QSize(32,32)
        self.bitmap.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
        self.bitmap.setMinimumSize(32,32)
        self.bitmap.resize(self.bitmap.sizeHint())

        #########
        self.addressButton = QPushButton("Rubrica")
        self.connect(self.addressButton, SIGNAL('clicked(bool)'),
                     self.addressButtonEventHandler)
        #########

        self.__set_properties()
        self.__do_layout()

        self.sendButton.setToolTip( "Invia l'SMS")
        self.stopButton.setToolTip("Interrompi l'invio")
        self.logButton.setToolTip("Esamina gli SMS inviati")
        self.check.setToolTip("Selezione per posticipare l'invio")
        self.addButton.setToolTip("Aggiungi il numero inserito in rubrica")
        self.deleteButton.setToolTip("Rimuovi l'elemento selezionato dalla" +\
                                     " rubrica")
        self.sentLabel.setToolTip("SMS inviati oggi con il gestore " +\
                                    self.getSender())

        #imposto la system tray icon
        self.tray = QSystemTrayIcon(icon)
        if self.tray.supportsMessages():
            self.traymessage = self.tray.showMessage
        if self.tray.isSystemTrayAvailable():
            self.tray.show()
            self.connect(self.tray,
                     SIGNAL('activated(QSystemTrayIcon::ActivationReason)'),
                     self.systemTrayEventHandler)
        else: self.tray = None

        #imposto il menu contestuale
        self.menu = QMenu("ermeSms", self)
        self.menu.addAction('Nascondi ermeSms',
                                          self.systemTrayEventHandler)
        self.menu.addSeparator()
        self.menu.addAction('Mostra Log', self.logButtonEventHandler)
        self.menu.addSeparator()
        self.debugMode = self.menu.addAction('Set Debug Mode On',
                                             self.debugMenuHandler)
        self.menu.addSeparator()
        self.menu.addAction('Esci', self.closeEvent)

        #Evento: il testo nella combobox cambia
        #PRIMA viene richiamato destinationComboBoxEventHandler
        #e POI updateLabel
        self.connect(self.destinationComboBox,
                     SIGNAL('editTextChanged(const QString&)'),
                     self.destinationComboBoxEventHandler)
        self.connect(self.destinationComboBox,
                     SIGNAL('editTextChanged(const QString&)'),
                     self.updateLabel)

        #Eventi: pressione di bottoni
        self.connect(self.addButton, SIGNAL('clicked(bool)'),
                     self.addButtonEventHandler)
        self.connect(self.addButton, SIGNAL('clicked(bool)'),
                     self.updateLabel)
        self.connect(self.deleteButton, SIGNAL('clicked(bool)'),
                     self.deleteButtonEventHandler)
        self.connect(self.deleteButton, SIGNAL('clicked(bool)'),
                     self.updateLabel)
        self.connect(self.logButton, SIGNAL('clicked(bool)'),
                     self.logButtonEventHandler)
        self.connect(self.stopButton, SIGNAL('clicked(bool)'),
                     self.stopButtonEventHandler)
        self.connect(self.sendButton, SIGNAL('clicked(bool)'),
                     self.sendButtonEventHandler)

        #Altri eventi che comportano aggiornamenti della barra di stato
        self.connect(self.messageTextCtrl, SIGNAL('textChanged()'),
                     self.updateLabel)

        for i in self.senderBoxes:
            self.connect(self.senderBoxes[i], SIGNAL('clicked(bool)'),
                     self.updateLabel)

        #Eventi personalizzati di comunicazione tra Thread e system tray
        self.connect(self, SIGNAL('passRequest'),
                     self.passRequestEventHandler)
        self.connect(self, SIGNAL('proxyRequest'),
                     self.proxyRequestEventHandler)
        self.connect(self, SIGNAL('gaugeUpdate'),
                     self.gaugeUpdateEventHandler)
        self.connect(self, SIGNAL('criticalError'),
                     self.criticalSenderErrorHandler)
        self.connect(self, SIGNAL('userDecodeCaptcha'),
                     self.userDecodeCaptchaHandler)
        self.connect(self, SIGNAL('sentMessageUpdate'),
                     self.sentUpdateEventHandler)
        self.connect(self, SIGNAL('logSave'),
                     self.logSaveEventHandler)
        self.connect(self, SIGNAL('minimizeToTray'),
                     self.systemTrayEventHandler, Qt.QueuedConnection)

        #Se specificato da linea di comando, inserisco i parametri
        if (len(sys.argv) - 1 == 2) and sys.argv[1]=="-gui":
            self.destinationComboBox.setCurrentIndex(
                self.destinationComboBox.findText(sys.argv[2]))
        else:
            #altrimenti gli ultimi settaggi usati
            if self.pm.isLastUsedAvailable("destination"):
                self.destinationComboBox.setCurrentIndex(
                    self.destinationComboBox.findText(
                    self.pm.getLastUsed("destination")))

        #se il messaggio precedente non è stato inviato
        if self.pm.isLastUsedAvailable("message"):
            self.messageTextCtrl.setText(self.pm.getLastUsed("message"))
        #se trova i settaggi per il sender dell'ultimo destinatario
        if self.pm.isLastUsedAvailable("destination"):
            if self.pm.isContactSenderAvailable(
                self.pm.getLastUsed("destination")):
                if self.senderBoxes.has_key(self.pm.getContactSender(
                    self.pm.getLastUsed("destination"))):
                    self.senderBoxes[self.pm.getContactSender(
                        self.pm.getLastUsed("destination"))].setChecked(True)
            #altrimenti l'ultimo selezionato
            elif self.pm.isLastUsedAvailable("sender"):
                if self.senderBoxes.has_key(self.pm.getLastUsed("sender")):
                    self.senderBoxes[self.pm.getLastUsed(
                        "sender")].setChecked(True)

        #sposto al centro la Main
        posx = (QDesktopWidget().width()-self.width())/2
        posy = ((QDesktopWidget().height()/3*2)-self.height())/2
        self.move(posx,posy)

        #Per evitare di riscrivere codice di inizializzazione già presente
        #negli eventHandler, li avvio manualmente la prima volta
        self.destinationComboBoxEventHandler('init')
        self.updateLabel()
        self.updateSentMessages()
Example #11
0
    def updateLabel(self, event=None):
        """Aggiorna la barra dei messaggi segnalando all'utente eventuali
        problemi. Se vengono rilevati problemi, disabilita il bottone Invia"""
        canSend = True
        message = ""

        destString = unicode(self.destinationComboBox.currentText())

        #1- Segnalazioni di errore

        text = unicode(self.messageTextCtrl.toPlainText())

        if destString == "":
            message = "Inserisci un destinatario"
            canSend = False
        elif self.isNumber(destString) == False and \
             self.pm.isInContacts(destString)==False:
            message = "Non in rubrica"
            canSend = False
        elif self.isNumber(destString) and self.isValid(destString) == False:
            message = "Inserisci un numero di cellulare"
            canSend = False
        elif text == "":
            message = "Inserisci del testo nel messaggio"
            canSend = False

        #2- Segnalazioni secondarie (da mostrare se non ci sono
        #errori
        if canSend:
            if not event or event == True:
                #2.1- L'utente ha appena scritto un carattere del mesaggio
                #     o ha selezionato un nuovo sender
                sender = Sender.getPlugins()[self.getSender()]
                texts = sender.splitText(sender.replaceNonAscii(text))
                textCount = len(texts)
                lastTextCharCount = len(texts[-1])
                remainingCharCount = sender.maxLength - lastTextCharCount
                newCharCount = sender.newCharCount(text)
                if textCount == 1:
                    message = "Scritto un messaggio: "
                else:
                    message = "Scritti " + str(textCount) + " messaggi: "
                if remainingCharCount == 0:
                    message += "messaggio riempito."
                else:
                    message += "mancano "+str(remainingCharCount)+\
                               " caratteri a riempire il messaggio"
                if textCount > 1 and not newCharCount == sender.maxLength:
                    message += "\ne togli "+str(newCharCount)+" caratteri pe"+\
                               "r scrivere un messaggio in meno."
            else:
                #2.2- L'utente ha appena scritto un carattere del destinatario
                if self.pm.isInContacts(destString):
                    message = "In rubrica con il numero "+\
                              self.pm.lookup(destString)
                elif self.isValid(destString):
                    message = "Puoi salvare questo numero in rubrica"

        #aggiorno il label sent sender
        self.updateSentMessages()

        #Aggiorno la grafica
        self.messageLabel.setText(message)
        self.gauge.hide()
        if canSend:
            self.setIcon(getOkData())
        else:
            self.setIcon(getErrorData())
        self.sendButton.setEnabled(canSend)
Example #12
0
    def __init__(self):
        try:
            flag = Qt.WindowFlags(Qt.CustomizeWindowHint
                                  | Qt.WindowSystemMenuHint
                                  | Qt.WindowMinimizeButtonHint
                                  | Qt.WindowCloseButtonHint)
            self.defaultFlag = Qt.WindowFlags(Qt.CustomizeWindowHint
                                              | Qt.WindowTitleHint
                                              | Qt.WindowSystemMenuHint
                                              | Qt.WindowCloseButtonHint)
        except:
            flag = Qt.WindowFlags()
            self.defaultFlag = Qt.WindowFlags()

        QFrame.__init__(self, None, flag)
        self.setWindowState(Qt.WindowActive)

        #Icona della titlebar
        pixmap = QPixmap()
        pixmap.loadFromData(getIconData())
        icon = QIcon()
        icon.addPixmap(pixmap)
        self.setWindowIcon(icon)

        self.label = QLabel("A:")
        self.destinationComboBox = QComboBox()
        self.destinationComboBox.setInsertPolicy(QComboBox.NoInsert)
        self.destinationComboBox.setEditable(True)
        self.destinationComboBox.completer().setCaseSensitivity(
            Qt.CaseSensitive)
        self.fillContacts()
        self.deleteButton = QPushButton("Cancella")
        self.addButton = QPushButton("Metti in rubrica")
        self.label.setMinimumHeight(self.addButton.minimumSizeHint().height())

        self.messageTextCtrl = QTextEdit("Inserisci il tuo messaggio qui.")
        self.messageTextCtrl.setTabChangesFocus(True)
        self.messageTextCtrl.setMinimumHeight(70)
        if self.pm.isSenderListAvailable(Sender.getPlugins().keys()) == False:
            scd = SenderChoicesDialog(self)
            result = scd.exec_()
            if result == 0:
                senderList = Sender.getPlugins().keys()
            else:
                senderList = scd.getSenderList()
                self.pm.setSenderList(senderList, Sender.getPlugins().keys())
        else:
            senderList = self.pm.getSenderList()
        self.senderBoxes = {}
        self.senderRadioBox = QGroupBox("Scegli il sito per l'invio")
        for i in senderList:
            self.senderBoxes[i] = QRadioButton(i)
        self.senderBoxes[senderList[0]].setChecked(True)
        self.logButton = QPushButton("Apri Registro")
        self.sentLabel = QLabel("Inviati: 0")
        self.check = QCheckBox("Posticipa invio")
        self.sendButton = QPushButton("Invia!")
        self.stopButton = QPushButton("FERMA!")
        self.messageLabel = QLabel("Non in rubrica")
        self.gauge = QProgressBar()
        self.gauge.setRange(0, 1000)
        self.gauge.setMinimumHeight(32)
        self.normalcursor = self.cursor()
        self.waitcursor = QCursor(Qt.BusyCursor)

        self.bitmap = QLabel()
        self.iconsize = QSize(32, 32)
        self.bitmap.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
        self.bitmap.setMinimumSize(32, 32)
        self.bitmap.resize(self.bitmap.sizeHint())

        #########
        self.addressButton = QPushButton("Rubrica")
        self.connect(self.addressButton, SIGNAL('clicked(bool)'),
                     self.addressButtonEventHandler)
        #########

        self.__set_properties()
        self.__do_layout()

        self.sendButton.setToolTip("Invia l'SMS")
        self.stopButton.setToolTip("Interrompi l'invio")
        self.logButton.setToolTip("Esamina gli SMS inviati")
        self.check.setToolTip("Selezione per posticipare l'invio")
        self.addButton.setToolTip("Aggiungi il numero inserito in rubrica")
        self.deleteButton.setToolTip("Rimuovi l'elemento selezionato dalla" +\
                                     " rubrica")
        self.sentLabel.setToolTip("SMS inviati oggi con il gestore " +\
                                    self.getSender())

        #imposto la system tray icon
        self.tray = QSystemTrayIcon(icon)
        if self.tray.supportsMessages():
            self.traymessage = self.tray.showMessage
        if self.tray.isSystemTrayAvailable():
            self.tray.show()
            self.connect(
                self.tray,
                SIGNAL('activated(QSystemTrayIcon::ActivationReason)'),
                self.systemTrayEventHandler)
        else:
            self.tray = None

        #imposto il menu contestuale
        self.menu = QMenu("ermeSms", self)
        self.menu.addAction('Nascondi ermeSms', self.systemTrayEventHandler)
        self.menu.addSeparator()
        self.menu.addAction('Mostra Log', self.logButtonEventHandler)
        self.menu.addSeparator()
        self.debugMode = self.menu.addAction('Set Debug Mode On',
                                             self.debugMenuHandler)
        self.menu.addSeparator()
        self.menu.addAction('Esci', self.closeEvent)

        #Evento: il testo nella combobox cambia
        #PRIMA viene richiamato destinationComboBoxEventHandler
        #e POI updateLabel
        self.connect(self.destinationComboBox,
                     SIGNAL('editTextChanged(const QString&)'),
                     self.destinationComboBoxEventHandler)
        self.connect(self.destinationComboBox,
                     SIGNAL('editTextChanged(const QString&)'),
                     self.updateLabel)

        #Eventi: pressione di bottoni
        self.connect(self.addButton, SIGNAL('clicked(bool)'),
                     self.addButtonEventHandler)
        self.connect(self.addButton, SIGNAL('clicked(bool)'), self.updateLabel)
        self.connect(self.deleteButton, SIGNAL('clicked(bool)'),
                     self.deleteButtonEventHandler)
        self.connect(self.deleteButton, SIGNAL('clicked(bool)'),
                     self.updateLabel)
        self.connect(self.logButton, SIGNAL('clicked(bool)'),
                     self.logButtonEventHandler)
        self.connect(self.stopButton, SIGNAL('clicked(bool)'),
                     self.stopButtonEventHandler)
        self.connect(self.sendButton, SIGNAL('clicked(bool)'),
                     self.sendButtonEventHandler)

        #Altri eventi che comportano aggiornamenti della barra di stato
        self.connect(self.messageTextCtrl, SIGNAL('textChanged()'),
                     self.updateLabel)

        for i in self.senderBoxes:
            self.connect(self.senderBoxes[i], SIGNAL('clicked(bool)'),
                         self.updateLabel)

        #Eventi personalizzati di comunicazione tra Thread e system tray
        self.connect(self, SIGNAL('passRequest'), self.passRequestEventHandler)
        self.connect(self, SIGNAL('proxyRequest'),
                     self.proxyRequestEventHandler)
        self.connect(self, SIGNAL('gaugeUpdate'), self.gaugeUpdateEventHandler)
        self.connect(self, SIGNAL('criticalError'),
                     self.criticalSenderErrorHandler)
        self.connect(self, SIGNAL('userDecodeCaptcha'),
                     self.userDecodeCaptchaHandler)
        self.connect(self, SIGNAL('sentMessageUpdate'),
                     self.sentUpdateEventHandler)
        self.connect(self, SIGNAL('logSave'), self.logSaveEventHandler)
        self.connect(self, SIGNAL('minimizeToTray'),
                     self.systemTrayEventHandler, Qt.QueuedConnection)

        #Se specificato da linea di comando, inserisco i parametri
        if (len(sys.argv) - 1 == 2) and sys.argv[1] == "-gui":
            self.destinationComboBox.setCurrentIndex(
                self.destinationComboBox.findText(sys.argv[2]))
        else:
            #altrimenti gli ultimi settaggi usati
            if self.pm.isLastUsedAvailable("destination"):
                self.destinationComboBox.setCurrentIndex(
                    self.destinationComboBox.findText(
                        self.pm.getLastUsed("destination")))

        #se il messaggio precedente non è stato inviato
        if self.pm.isLastUsedAvailable("message"):
            self.messageTextCtrl.setText(self.pm.getLastUsed("message"))
        #se trova i settaggi per il sender dell'ultimo destinatario
        if self.pm.isLastUsedAvailable("destination"):
            if self.pm.isContactSenderAvailable(
                    self.pm.getLastUsed("destination")):
                if self.senderBoxes.has_key(
                        self.pm.getContactSender(
                            self.pm.getLastUsed("destination"))):
                    self.senderBoxes[self.pm.getContactSender(
                        self.pm.getLastUsed("destination"))].setChecked(True)
            #altrimenti l'ultimo selezionato
            elif self.pm.isLastUsedAvailable("sender"):
                if self.senderBoxes.has_key(self.pm.getLastUsed("sender")):
                    self.senderBoxes[self.pm.getLastUsed("sender")].setChecked(
                        True)

        #sposto al centro la Main
        posx = (QDesktopWidget().width() - self.width()) / 2
        posy = ((QDesktopWidget().height() / 3 * 2) - self.height()) / 2
        self.move(posx, posy)

        #Per evitare di riscrivere codice di inizializzazione già presente
        #negli eventHandler, li avvio manualmente la prima volta
        self.destinationComboBoxEventHandler('init')
        self.updateLabel()
        self.updateSentMessages()
Example #13
0
    def run(self):
        """Spedisce un messaggio e aggiorna la grafica."""
        #imposta senderName e identifica l'invio offline
        senderName = self.senderName
        sender = Sender.getPlugins()[senderName]
                       
        done = False
        hadError = False
        while done == False:
            try:
                reg = {}
                dn = self.dest
                if sender.requiresRegistration:
                    for i in sender.requiresRegistration:
                        reg[i] = self.pm.getAccount(senderName,i,
                                                    self.masterKey)
                if self.mf.isValid(dn)==False:
                    dn = self.pm.lookup(dn)
                if self.pm.isProxyEnabled():
                    proxy = self.pm.getProxy()
                else:
                    proxy = ''

                #resetta la gauge
                self.mf.gaugeIncrement(0)                     
              
                sender.send(proxy, dn, self.text, reg, self.mf)

                #log
                self.mf.emit(SIGNAL('logSave'), senderName, self.dest,
                               sender.replaceNonAscii(self.text))
                #salvo il gestore
                self.pm.setContactSender(self.dest,senderName)
                #aggiungo 1 ai mex inviati
                textCount=sender.countTexts(sender.replaceNonAscii(self.text))
                if self.pm.isSentSenderAvailable(senderName):
                    sentmessage = int(self.pm.getSentSender(senderName))+\
                                  textCount
                else: sentmessage = textCount
                self.pm.setSentSender(senderName,str(sentmessage))
                
                done = True
                
            except PreferenceManagerError:
                data = {'message' : "Immetti dei dati validi per accedere " + \
                    "al sito " + senderName }
                data['request'] = sender.requiresRegistration
                self.mf.emit(SIGNAL('passRequest'), data)
                data = self.mf.qReq.get(True)
                if not data:
                    done = True
                    hadError = u"L'ultimo SMS non è stato" +\
                               u" inviato a causa di un errore."                   
                else:
                    for i in sender.requiresRegistration:
                        self.pm.addAccount(i,data[i],senderName,self.masterKey)
            except SiteAuthError:
                data = {'message' : "Dati inseriti non validi, " + \
                          "reimmetterli (sito "+senderName+")"}
                data['request']= sender.requiresRegistration
                for i in data['request']:
                    data[i]= self.pm.getAccount(senderName,i,self.masterKey)
                self.mf.emit(SIGNAL('passRequest'), data)
                data = self.mf.qReq.get(True)
                if not data:
                    done = True
                    hadError = u"L'ultimo SMS non è stato" +\
                               u" inviato a causa di un errore."                   
                else:
                    self.pm.clearAccount(senderName)
                    for i in sender.requiresRegistration:
                        self.pm.addAccount(i,data[i],senderName,self.masterKey)
            except ConnectionError:        
                self.mf.emit(SIGNAL('proxyRequest'))
                data = self.mf.qReq.get(True)
                if not data:
                    done = True
                    hadError = u"L'ultimo SMS non è stato" +\
                               u" inviato a causa di un errore."
            except StopError:
                done = True
                hadError = u"L'ultimo SMS non è stato inviato per" + \
                           u" interruzione dell'utente."                    
            except (SiteConnectionError, SiteCustomError, SenderError,
                    CaptchaError, NotFoundError), e:
                done = True                  
                hadError = u"L'ultimo SMS non è stato" +\
                           u" inviato a causa di un errore."
                self.mf.emit(SIGNAL('criticalError'), e.__str__())
            except:
Example #14
0
    def run(self):
        """Spedisce un messaggio e aggiorna la grafica."""
        #imposta senderName e identifica l'invio offline
        senderName = self.senderName
        sender = Sender.getPlugins()[senderName]

        done = False
        hadError = False
        while done == False:
            try:
                reg = {}
                dn = self.dest
                if sender.requiresRegistration:
                    for i in sender.requiresRegistration:
                        reg[i] = self.pm.getAccount(senderName, i,
                                                    self.masterKey)
                if self.mf.isValid(dn) == False:
                    dn = self.pm.lookup(dn)
                if self.pm.isProxyEnabled():
                    proxy = self.pm.getProxy()
                else:
                    proxy = ''

                #resetta la gauge
                self.mf.gaugeIncrement(0)

                sender.send(proxy, dn, self.text, reg, self.mf)

                #log
                self.mf.emit(SIGNAL('logSave'), senderName, self.dest,
                             sender.replaceNonAscii(self.text))
                #salvo il gestore
                self.pm.setContactSender(self.dest, senderName)
                #aggiungo 1 ai mex inviati
                textCount = sender.countTexts(sender.replaceNonAscii(
                    self.text))
                if self.pm.isSentSenderAvailable(senderName):
                    sentmessage = int(self.pm.getSentSender(senderName))+\
                                  textCount
                else:
                    sentmessage = textCount
                self.pm.setSentSender(senderName, str(sentmessage))

                done = True

            except PreferenceManagerError:
                data = {'message' : "Immetti dei dati validi per accedere " + \
                    "al sito " + senderName }
                data['request'] = sender.requiresRegistration
                self.mf.emit(SIGNAL('passRequest'), data)
                data = self.mf.qReq.get(True)
                if not data:
                    done = True
                    hadError = u"L'ultimo SMS non è stato" +\
                               u" inviato a causa di un errore."
                else:
                    for i in sender.requiresRegistration:
                        self.pm.addAccount(i, data[i], senderName,
                                           self.masterKey)
            except SiteAuthError:
                data = {'message' : "Dati inseriti non validi, " + \
                          "reimmetterli (sito "+senderName+")"}
                data['request'] = sender.requiresRegistration
                for i in data['request']:
                    data[i] = self.pm.getAccount(senderName, i, self.masterKey)
                self.mf.emit(SIGNAL('passRequest'), data)
                data = self.mf.qReq.get(True)
                if not data:
                    done = True
                    hadError = u"L'ultimo SMS non è stato" +\
                               u" inviato a causa di un errore."
                else:
                    self.pm.clearAccount(senderName)
                    for i in sender.requiresRegistration:
                        self.pm.addAccount(i, data[i], senderName,
                                           self.masterKey)
            except ConnectionError:
                self.mf.emit(SIGNAL('proxyRequest'))
                data = self.mf.qReq.get(True)
                if not data:
                    done = True
                    hadError = u"L'ultimo SMS non è stato" +\
                               u" inviato a causa di un errore."
            except StopError:
                done = True
                hadError = u"L'ultimo SMS non è stato inviato per" + \
                           u" interruzione dell'utente."
            except (SiteConnectionError, SiteCustomError, SenderError,
                    CaptchaError, NotFoundError), e:
                done = True
                hadError = u"L'ultimo SMS non è stato" +\
                           u" inviato a causa di un errore."
                self.mf.emit(SIGNAL('criticalError'), e.__str__())
            except:
Example #15
0
 def run(self):
     """Avvia questa interfaccia."""
     na = len(sys.argv) - 1
     exitCode = 0
     p = PreferenceManager.getInstance()
     cm = CodingManager.getInstance()
     try:
         if (na == 1):
             #Un solo argomento, lista rubrica o help
             arg1 = cm.unicodeArgv(sys.argv[1])
             if (arg1 == "-m" or arg1 == "--mostra"):
                 for name, number in p.getContacts().iteritems():
                     print cm.encodeStdout(name)+": "+cm.encodeStdout(number)
             else:
                 HelpUI.getInstance().run()
         elif (na == 2):
             #Due argomenti, numero e testo
             arg1 = cm.unicodeArgv(sys.argv[1])
             arg2 = cm.unicodeArgv(sys.argv[2])
             self.sendSMS(arg1, arg2, Sender.getPlugins().keys()[0])
         elif (na == 3):
             #Tre argomenti. Tre casi: "-a nome numero"
             #oppure "numero testo sender"
             arg1 = cm.unicodeArgv(sys.argv[1])
             arg2 = cm.unicodeArgv(sys.argv[2])
             arg3 = cm.unicodeArgv(sys.argv[3])
             if (arg1 == "-a" or arg1 == "--add"):
                 p.addContact(arg2, arg3)
                 print "Aggiunto!"
             else:
                 if p.isProxyEnabled() == True:
                     os.environ["http_proxy"] = p.getProxy()
                 self.sendSMS(arg1, arg2, arg3)
         elif (na == 4):
             #numero testo -p proxy
             arg1 = cm.unicodeArgv(sys.argv[1])
             arg2 = cm.unicodeArgv(sys.argv[2])
             arg3 = cm.unicodeArgv(sys.argv[3])
             arg4 = cm.unicodeArgv(sys.argv[4])
             if (arg3=="-p" or arg3=="--proxy"):
                 if arg4 != "no":
                     p.setProxy(arg4)
                 else:
                     p.unsetProxy()
                 if p.isProxyEnabled() == True:
                     os.environ["http_proxy"] = p.getProxy()
                 self.sendSMS(arg1, arg2, Sender.getPlugins().keys()[0])
             else:
                 HelpUI.getInstance().run()
         elif (na == 5):
             #numero testo sender -p proxy
             arg1 = cm.unicodeArgv(sys.argv[1])
             arg2 = cm.unicodeArgv(sys.argv[2])
             arg3 = cm.unicodeArgv(sys.argv[3])
             arg4 = cm.unicodeArgv(sys.argv[4])
             arg5 = cm.unicodeArgv(sys.argv[5])
             if (arg4=="-p" or arg4=="--proxy"):
                 if arg5 != "no":
                     p.setProxy(arg5)
                 else:
                     p.unsetProxy()
                 if p.isProxyEnabled() == True:
                     os.environ["http_proxy"] = p.getProxy()
                 self.sendSMS(arg1, arg2, arg3)
             else:
                 HelpUI.getInstance().run()
         else:
             HelpUI.getInstance().run()
     except NotFoundError, e:
         print cm.encodeStdout(e.__str__())
         exitCode = 1
Example #16
0
 def stopButtonEventHandler(self):
     """Gestisce l'evento di interruzione di invio"""
     Sender.getPlugins()[self.getSender()].stop = True
Example #17
0
    def updateLabel(self, event=None):
        """Aggiorna la barra dei messaggi segnalando all'utente eventuali
        problemi. Se vengono rilevati problemi, disabilita il bottone Invia"""
        canSend = True
        message = ""

        destString = unicode(self.destinationComboBox.currentText())

        #1- Segnalazioni di errore

        text = unicode(self.messageTextCtrl.toPlainText())

        if destString == "":
            message = "Inserisci un destinatario"
            canSend = False
        elif self.isNumber(destString) == False and \
             self.pm.isInContacts(destString)==False:
            message = "Non in rubrica"
            canSend = False
        elif self.isNumber(destString) and self.isValid(destString) == False:
            message = "Inserisci un numero di cellulare"
            canSend = False
        elif text == "":
            message = "Inserisci del testo nel messaggio"
            canSend = False

        #2- Segnalazioni secondarie (da mostrare se non ci sono
        #errori
        if canSend:
            if not event or event==True:
                #2.1- L'utente ha appena scritto un carattere del mesaggio
                #     o ha selezionato un nuovo sender
                sender = Sender.getPlugins()[self.getSender()]
                texts = sender.splitText(sender.replaceNonAscii(text))
                textCount = len(texts)
                lastTextCharCount = len(texts[-1])
                remainingCharCount = sender.maxLength - lastTextCharCount
                newCharCount = sender.newCharCount(text)
                if textCount==1:
                    message = "Scritto un messaggio: "
                else:
                    message = "Scritti "+str(textCount)+" messaggi: "
                if remainingCharCount==0:
                    message += "messaggio riempito."
                else:
                    message += "mancano "+str(remainingCharCount)+\
                               " caratteri a riempire il messaggio"
                if textCount > 1 and not newCharCount == sender.maxLength:
                    message += "\ne togli "+str(newCharCount)+" caratteri pe"+\
                               "r scrivere un messaggio in meno."
            else:
                #2.2- L'utente ha appena scritto un carattere del destinatario
                if self.pm.isInContacts(destString):
                    message = "In rubrica con il numero "+\
                              self.pm.lookup(destString)
                elif self.isValid(destString):
                    message = "Puoi salvare questo numero in rubrica"

        #aggiorno il label sent sender
        self.updateSentMessages()

        #Aggiorno la grafica
        self.messageLabel.setText(message)
        self.gauge.hide()
        if canSend:
            self.setIcon(getOkData())
        else:
            self.setIcon(getErrorData())
        self.sendButton.setEnabled(canSend)