@@ -447,7 +447,9 @@ def rerenderTabTree(self, tab):
447447 elif tab == 'chan' :
448448 treeWidget = self .ui .treeWidgetChans
449449
450- #treeWidget.clear()
450+ # sort ascending when creating
451+ if treeWidget .topLevelItemCount () == 0 :
452+ treeWidget .header ().setSortIndicator (0 , Qt .AscendingOrder )
451453
452454 # init dictionary
453455 db = {}
@@ -860,6 +862,10 @@ def loadSent(self, tableWidget, account, where="", what=""):
860862 else :
861863 where = "toaddress || fromaddress || subject || message"
862864
865+ tableWidget .setColumnHidden (0 , False )
866+ tableWidget .setColumnHidden (1 , True )
867+ tableWidget .setSortingEnabled (False )
868+
863869 sqlStatement = '''
864870 SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
865871 FROM sent WHERE fromaddress=? AND folder="sent" AND %s LIKE ?
@@ -868,60 +874,34 @@ def loadSent(self, tableWidget, account, where="", what=""):
868874
869875 while tableWidget .rowCount () > 0 :
870876 tableWidget .removeRow (0 )
871-
877+ acct = None
872878 queryreturn = sqlQuery (sqlStatement , account , what )
873879 for row in queryreturn :
874880 toAddress , fromAddress , subject , status , ackdata , lastactiontime = row
875881 subject = shared .fixPotentiallyInvalidUTF8Data (subject )
876-
877- if shared .config .has_section (fromAddress ):
878- fromLabel = shared .config .get (fromAddress , 'label' )
879- else :
880- fromLabel = fromAddress
881-
882- toLabel = ''
883- queryreturn = sqlQuery (
884- '''select label from addressbook where address=?''' , toAddress )
885- if queryreturn != []:
886- for row in queryreturn :
887- toLabel , = row
888- if toLabel == '' :
889- # It might be a broadcast message. We should check for that
890- # label.
891- queryreturn = sqlQuery (
892- '''select label from subscriptions where address=?''' , toAddress )
893-
894- if queryreturn != []:
895- for row in queryreturn :
896- toLabel , = row
897-
898- if toLabel == '' :
899- if shared .config .has_section (toAddress ):
900- toLabel = shared .config .get (toAddress , 'label' )
901- if toLabel == '' :
902- toLabel = toAddress
882+ if acct is None :
883+ acct = accountClass (fromAddress )
884+ acct .parseMessage (toAddress , fromAddress , subject , "" )
903885
904886 tableWidget .insertRow (0 )
905- toAddressItem = QtGui .QTableWidgetItem (unicode (toLabel , 'utf-8' ))
906- toAddressItem .setToolTip (unicode (toLabel , 'utf-8' ))
887+ toAddressItem = QtGui .QTableWidgetItem (unicode (acct . toLabel , 'utf-8' ))
888+ toAddressItem .setToolTip (unicode (acct . toLabel , 'utf-8' ))
907889 toAddressItem .setIcon (avatarize (toAddress ))
908890 toAddressItem .setData (Qt .UserRole , str (toAddress ))
909891 toAddressItem .setFlags (
910892 QtCore .Qt .ItemIsSelectable | QtCore .Qt .ItemIsEnabled )
911893 tableWidget .setItem (0 , 0 , toAddressItem )
912894
913- if fromLabel == '' :
914- fromLabel = fromAddress
915- fromAddressItem = QtGui .QTableWidgetItem (unicode (fromLabel , 'utf-8' ))
916- fromAddressItem .setToolTip (unicode (fromLabel , 'utf-8' ))
895+ fromAddressItem = QtGui .QTableWidgetItem (unicode (acct .fromLabel , 'utf-8' ))
896+ fromAddressItem .setToolTip (unicode (acct .fromLabel , 'utf-8' ))
917897 fromAddressItem .setIcon (avatarize (fromAddress ))
918898 fromAddressItem .setData (Qt .UserRole , str (fromAddress ))
919899 fromAddressItem .setFlags (
920900 QtCore .Qt .ItemIsSelectable | QtCore .Qt .ItemIsEnabled )
921901 tableWidget .setItem (0 , 1 , fromAddressItem )
922902
923- subjectItem = QtGui .QTableWidgetItem (unicode (subject , 'utf-8' ))
924- subjectItem .setToolTip (unicode (subject , 'utf-8' ))
903+ subjectItem = QtGui .QTableWidgetItem (unicode (acct . subject , 'utf-8' ))
904+ subjectItem .setToolTip (unicode (acct . subject , 'utf-8' ))
925905 subjectItem .setFlags (
926906 QtCore .Qt .ItemIsSelectable | QtCore .Qt .ItemIsEnabled )
927907 tableWidget .setItem (0 , 2 , subjectItem )
@@ -972,7 +952,9 @@ def loadSent(self, tableWidget, account, where="", what=""):
972952 newItem .setFlags (
973953 QtCore .Qt .ItemIsSelectable | QtCore .Qt .ItemIsEnabled )
974954 tableWidget .setItem (0 , 3 , newItem )
975- tableWidget .sortItems (3 , Qt .DescendingOrder )
955+
956+ tableWidget .setSortingEnabled (False )
957+ tableWidget .horizontalHeader ().setSortIndicator (3 , Qt .DescendingOrder )
976958 tableWidget .keyPressEvent = self .tableWidgetInboxKeyPressEvent
977959
978960 # Load messages from database file
@@ -993,62 +975,43 @@ def loadMessagelist(self, tableWidget, account, folder="inbox", where="", what="
993975 else :
994976 where = "toaddress || fromaddress || subject || message"
995977
996- sqlStatement = '''
997- SELECT msgid, toaddress, fromaddress, subject, received, read
998- FROM inbox WHERE toaddress=? AND folder=? AND %s LIKE ?
999- ORDER BY received
1000- ''' % (where )
978+ if folder != False :
979+ sqlStatement = '''
980+ SELECT folder, msgid, toaddress, fromaddress, subject, received, read
981+ FROM inbox WHERE toaddress=? AND folder=? AND %s LIKE ?
982+ ORDER BY received
983+ ''' % (where )
984+ queryreturn = sqlQuery (sqlStatement , account , folder , what )
985+ else :
986+ sqlStatement = '''
987+ SELECT folder, msgid, toaddress, fromaddress, subject, received, read
988+ FROM inbox WHERE toaddress=? AND folder != "trash" AND %s LIKE ?
989+ ORDER BY received
990+ ''' % (where )
991+ queryreturn = sqlQuery (sqlStatement , account , what )
1001992
1002993 while tableWidget .rowCount () > 0 :
1003994 tableWidget .removeRow (0 )
1004995
996+ tableWidget .setColumnHidden (0 , True )
997+ tableWidget .setColumnHidden (1 , False )
998+ tableWidget .setSortingEnabled (False )
999+
10051000 font = QFont ()
10061001 font .setBold (True )
1007- queryreturn = sqlQuery (sqlStatement , account , folder , what )
10081002 acct = None
10091003 for row in queryreturn :
1010- msgid , toAddress , fromAddress , subject , received , read = row
1004+ msgfolder , msgid , toAddress , fromAddress , subject , received , read = row
10111005 if acct is None :
10121006 acct = accountClass (toAddress )
10131007 subject = shared .fixPotentiallyInvalidUTF8Data (subject )
10141008 acct .parseMessage (toAddress , fromAddress , subject , "" )
1015- try :
1016- if toAddress == self .str_broadcast_subscribers :
1017- toLabel = self .str_broadcast_subscribers
1018- else :
1019- toLabel = shared .config .get (toAddress , 'label' )
1020- except :
1021- toLabel = ''
1022- if toLabel == '' :
1023- toLabel = toAddress
1024-
1025- fromLabel = ''
1026- if type (acct ) == MailchuckAccount :
1027- fromLabel = acct .fromAddress
1028- if shared .config .has_section (fromAddress ):
1029- fromLabel = shared .config .get (fromAddress , 'label' )
1030-
1031- if fromLabel == '' : # If the fromAddress isn't one of our addresses and isn't a chan
1032- queryreturn = sqlQuery (
1033- '''select label from addressbook where address=?''' , fromAddress )
1034- if queryreturn != []:
1035- for row in queryreturn :
1036- fromLabel , = row
1037-
1038- if fromLabel == '' : # If this address wasn't in our address book...
1039- queryreturn = sqlQuery (
1040- '''select label from subscriptions where address=?''' , fromAddress )
1041- if queryreturn != []:
1042- for row in queryreturn :
1043- fromLabel , = row
1044- if fromLabel == '' :
1045- fromLabel = fromAddress
10461009
10471010 # message row
10481011 tableWidget .insertRow (0 )
10491012 # to
1050- to_item = QtGui .QTableWidgetItem (unicode (toLabel , 'utf-8' ))
1051- to_item .setToolTip (unicode (toLabel , 'utf-8' ))
1013+ to_item = QtGui .QTableWidgetItem (unicode (acct . toLabel , 'utf-8' ))
1014+ to_item .setToolTip (unicode (acct . toLabel , 'utf-8' ))
10521015 to_item .setFlags (
10531016 QtCore .Qt .ItemIsSelectable | QtCore .Qt .ItemIsEnabled )
10541017 if not read :
@@ -1061,8 +1024,8 @@ def loadMessagelist(self, tableWidget, account, folder="inbox", where="", what="
10611024 to_item .setIcon (avatarize (toAddress ))
10621025 tableWidget .setItem (0 , 0 , to_item )
10631026 # from
1064- from_item = QtGui .QTableWidgetItem (unicode (fromLabel , 'utf-8' ))
1065- from_item .setToolTip (unicode (fromLabel , 'utf-8' ))
1027+ from_item = QtGui .QTableWidgetItem (unicode (acct . fromLabel , 'utf-8' ))
1028+ from_item .setToolTip (unicode (acct . fromLabel , 'utf-8' ))
10661029 from_item .setFlags (
10671030 QtCore .Qt .ItemIsSelectable | QtCore .Qt .ItemIsEnabled )
10681031 if not read :
@@ -1091,7 +1054,8 @@ def loadMessagelist(self, tableWidget, account, folder="inbox", where="", what="
10911054 time_item .setFont (font )
10921055 tableWidget .setItem (0 , 3 , time_item )
10931056
1094- tableWidget .sortItems (3 , Qt .DescendingOrder )
1057+ tableWidget .horizontalHeader ().setSortIndicator (3 , Qt .DescendingOrder )
1058+ tableWidget .setSortingEnabled (True )
10951059 tableWidget .keyPressEvent = self .tableWidgetInboxKeyPressEvent
10961060
10971061 # create application indicator
@@ -1761,8 +1725,8 @@ def drawTrayIcon(self, iconFileName, inboxUnreadCount):
17611725 def changedInboxUnread (self , row = None ):
17621726 self .drawTrayIcon (self .currentTrayIconFileName , self .findInboxUnreadCount ())
17631727 self .rerenderTabTreeMessages ()
1764- if not row is None :
1765- row [1 ], row [6 ]
1728+ # if not row is None:
1729+ # row[1], row[6]
17661730 if self .ui .tabWidget .currentIndex () == 2 :
17671731 self .rerenderTabTreeSubscriptions ()
17681732 elif self .ui .tabWidget .currentIndex () == 3 :
@@ -2214,35 +2178,23 @@ def displayNewSentMessage(self, toAddress, toLabel, fromAddress, subject, messag
22142178 return
22152179 subject = shared .fixPotentiallyInvalidUTF8Data (subject )
22162180 message = shared .fixPotentiallyInvalidUTF8Data (message )
2217- try :
2218- fromLabel = shared .config .get (fromAddress , 'label' )
2219- except :
2220- fromLabel = ''
2221- if fromLabel == '' :
2222- fromLabel = fromAddress
2181+ acct = accountClass (fromAddress )
2182+ acct .parseMessage (toAddress , fromAddress , subject , message )
22232183
22242184 self .ui .tableWidgetInbox .setSortingEnabled (False )
22252185 self .ui .tableWidgetInbox .insertRow (0 )
2226- if toLabel == '' :
2227- newItem = QtGui .QTableWidgetItem (unicode (toAddress , 'utf-8' ))
2228- newItem .setToolTip (unicode (toAddress , 'utf-8' ))
2229- else :
2230- newItem = QtGui .QTableWidgetItem (unicode (toLabel , 'utf-8' ))
2231- newItem .setToolTip (unicode (toLabel , 'utf-8' ))
2186+ newItem = QtGui .QTableWidgetItem (unicode (acct .toLabel , 'utf-8' ))
2187+ newItem .setToolTip (unicode (acct .toLabel , 'utf-8' ))
22322188 newItem .setData (Qt .UserRole , str (toAddress ))
22332189 newItem .setIcon (avatarize (toAddress ))
22342190 self .ui .tableWidgetInbox .setItem (0 , 0 , newItem )
2235- if fromLabel == '' :
2236- newItem = QtGui .QTableWidgetItem (unicode (fromAddress , 'utf-8' ))
2237- newItem .setToolTip (unicode (fromAddress , 'utf-8' ))
2238- else :
2239- newItem = QtGui .QTableWidgetItem (unicode (fromLabel , 'utf-8' ))
2240- newItem .setToolTip (unicode (fromLabel , 'utf-8' ))
2191+ newItem = QtGui .QTableWidgetItem (unicode (acct .fromLabel , 'utf-8' ))
2192+ newItem .setToolTip (unicode (acct .fromLabel , 'utf-8' ))
22412193 newItem .setData (Qt .UserRole , str (fromAddress ))
22422194 newItem .setIcon (avatarize (fromAddress ))
22432195 self .ui .tableWidgetInbox .setItem (0 , 1 , newItem )
2244- newItem = QtGui .QTableWidgetItem (unicode (subject , 'utf-8)' ))
2245- newItem .setToolTip (unicode (subject , 'utf-8)' ))
2196+ newItem = QtGui .QTableWidgetItem (unicode (acct . subject , 'utf-8)' ))
2197+ newItem .setToolTip (unicode (acct . subject , 'utf-8)' ))
22462198 #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
22472199 self .ui .tableWidgetInbox .setItem (0 , 2 , newItem )
22482200 # newItem = QtGui.QTableWidgetItem('Doing work necessary to send
@@ -2257,40 +2209,17 @@ def displayNewSentMessage(self, toAddress, toLabel, fromAddress, subject, messag
22572209 self .ui .tableWidgetInbox .setSortingEnabled (True )
22582210
22592211 def displayNewInboxMessage (self , inventoryHash , toAddress , fromAddress , subject , message ):
2260- if self .getCurrentFolder () != "inbox" or self .getCurrentAccount () != toAddress :
2212+ if ( self .getCurrentFolder () != "inbox" and self . getCurrentFolder () != False ) or self .getCurrentAccount () != toAddress :
22612213 return
22622214 subject = shared .fixPotentiallyInvalidUTF8Data (subject )
2263- fromLabel = ''
2264- queryreturn = sqlQuery (
2265- '''select label from addressbook where address=?''' , fromAddress )
2266- if queryreturn != []:
2267- for row in queryreturn :
2268- fromLabel , = row
2269- else :
2270- # There might be a label in the subscriptions table
2271- queryreturn = sqlQuery (
2272- '''select label from subscriptions where address=?''' , fromAddress )
2273- if queryreturn != []:
2274- for row in queryreturn :
2275- fromLabel , = row
2276-
2277- try :
2278- if toAddress == self .str_broadcast_subscribers :
2279- toLabel = self .str_broadcast_subscribers
2280- else :
2281- toLabel = shared .config .get (toAddress , 'label' )
2282- except :
2283- toLabel = ''
2284- if toLabel == '' :
2285- toLabel = toAddress
2215+ acct = accountClass (toAddress )
2216+ acct .parseMessage (toAddress , fromAddress , subject , message )
22862217
22872218 font = QFont ()
22882219 font .setBold (True )
22892220 self .ui .tableWidgetInbox .setSortingEnabled (False )
2290- account = accountClass (toAddress )
2291- account .parseMessage (toAddress , fromAddress , subject , message )
2292- newItem = QtGui .QTableWidgetItem (unicode (toLabel , 'utf-8' ))
2293- newItem .setToolTip (unicode (toLabel , 'utf-8' ))
2221+ newItem = QtGui .QTableWidgetItem (unicode (acct .toLabel , 'utf-8' ))
2222+ newItem .setToolTip (unicode (acct .toLabel , 'utf-8' ))
22942223 newItem .setFont (font )
22952224 newItem .setData (Qt .UserRole , str (toAddress ))
22962225 if shared .safeConfigGetBoolean (str (toAddress ), 'mailinglist' ):
@@ -2301,27 +2230,16 @@ def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject,
23012230 newItem .setIcon (avatarize (toAddress ))
23022231 self .ui .tableWidgetInbox .setItem (0 , 0 , newItem )
23032232
2304- if type (account ) is MailchuckAccount :
2305- newItem = QtGui .QTableWidgetItem (unicode (account .fromAddress , 'utf-8' ))
2306- newItem .setToolTip (unicode (account .fromAddress , 'utf-8' ))
2307- if shared .config .getboolean ('bitmessagesettings' , 'showtraynotifications' ):
2308- self .notifierShow (unicode (_translate ("MainWindow" ,'New Message' ).toUtf8 (),'utf-8' ), unicode (_translate ("MainWindow" ,'From ' ).toUtf8 (),'utf-8' ) + unicode (account .fromAddress , 'utf-8' ), self .SOUND_UNKNOWN , None )
2309- elif fromLabel == '' :
2310- newItem = QtGui .QTableWidgetItem (unicode (fromAddress , 'utf-8' ))
2311- newItem .setToolTip (unicode (fromAddress , 'utf-8' ))
2312- if shared .config .getboolean ('bitmessagesettings' , 'showtraynotifications' ):
2313- self .notifierShow (unicode (_translate ("MainWindow" ,'New Message' ).toUtf8 (),'utf-8' ), unicode (_translate ("MainWindow" ,'From ' ).toUtf8 (),'utf-8' ) + unicode (fromAddress , 'utf-8' ), self .SOUND_UNKNOWN , None )
2314- else :
2315- newItem = QtGui .QTableWidgetItem (unicode (fromLabel , 'utf-8' ))
2316- newItem .setToolTip (unicode (unicode (fromLabel , 'utf-8' )))
2317- if shared .config .getboolean ('bitmessagesettings' , 'showtraynotifications' ):
2318- self .notifierShow (unicode (_translate ("MainWindow" ,'New Message' ).toUtf8 (),'utf-8' ), unicode (_translate ("MainWindow" ,'From ' ).toUtf8 (),'utf-8' ) + unicode (fromLabel , 'utf-8' ), self .SOUND_KNOWN , unicode (fromLabel , 'utf-8' ))
2233+ newItem = QtGui .QTableWidgetItem (unicode (acct .fromLabel , 'utf-8' ))
2234+ newItem .setToolTip (unicode (acct .fromLabel , 'utf-8' ))
2235+ if shared .config .getboolean ('bitmessagesettings' , 'showtraynotifications' ):
2236+ self .notifierShow (unicode (_translate ("MainWindow" ,'New Message' ).toUtf8 (),'utf-8' ), unicode (_translate ("MainWindow" ,'From ' ).toUtf8 (),'utf-8' ) + unicode (acct .fromLabel , 'utf-8' ), self .SOUND_UNKNOWN , None )
23192237 newItem .setData (Qt .UserRole , str (fromAddress ))
23202238 newItem .setFont (font )
23212239 newItem .setIcon (avatarize (fromAddress ))
23222240 self .ui .tableWidgetInbox .setItem (0 , 1 , newItem )
2323- newItem = QtGui .QTableWidgetItem (unicode (subject , 'utf-8)' ))
2324- newItem .setToolTip (unicode (account .subject , 'utf-8)' ))
2241+ newItem = QtGui .QTableWidgetItem (unicode (acct . subject , 'utf-8)' ))
2242+ newItem .setToolTip (unicode (acct .subject , 'utf-8)' ))
23252243 #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
23262244 newItem .setFont (font )
23272245 self .ui .tableWidgetInbox .setItem (0 , 2 , newItem )
@@ -2332,7 +2250,7 @@ def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject,
23322250 newItem .setFont (font )
23332251 self .ui .tableWidgetInbox .setItem (0 , 3 , newItem )
23342252 self .ui .tableWidgetInbox .setSortingEnabled (True )
2335- self .ubuntuMessagingMenuUpdate (True , newItem , toLabel )
2253+ self .ubuntuMessagingMenuUpdate (True , newItem , self . toLabel )
23362254
23372255 def click_pushButtonAddAddressBook (self ):
23382256 self .AddAddressDialogInstance = AddAddressDialog (self )
@@ -2953,11 +2871,14 @@ def on_action_InboxTrash(self):
29532871 tableWidget = self .getCurrentMessagelist ()
29542872 if not tableWidget :
29552873 return
2874+ unread = False
29562875 while tableWidget .selectedIndexes () != []:
29572876 currentRow = tableWidget .selectedIndexes ()[0 ].row ()
29582877 inventoryHashToTrash = str (tableWidget .item (
29592878 currentRow , 3 ).data (Qt .UserRole ).toPyObject ())
29602879 sqlExecute ('''UPDATE inbox SET folder='trash' WHERE msgid=?''' , inventoryHashToTrash )
2880+ if tableWidget .item (currentRow , 0 ).font ().bold ():
2881+ unread = True
29612882 self .ui .textEditInboxMessage .setText ("" )
29622883 tableWidget .removeRow (currentRow )
29632884 self .statusBar ().showMessage (_translate (
@@ -2966,6 +2887,8 @@ def on_action_InboxTrash(self):
29662887 tableWidget .selectRow (currentRow )
29672888 else :
29682889 tableWidget .selectRow (currentRow - 1 )
2890+ if unread :
2891+ changedInboxUnread ()
29692892
29702893 def on_action_InboxSaveMessageAs (self ):
29712894 tableWidget = self .getCurrentMessagelist ()
@@ -3301,9 +3224,8 @@ def getCurrentFolder(self):
33013224 treeWidget = self .ui .treeWidgetYourIdentities
33023225 if treeWidget :
33033226 currentItem = treeWidget .currentItem ()
3304- if currentItem :
3305- account = currentItem .folderName
3306- return account
3227+ if currentItem and hasattr (currentItem , 'folderName' ):
3228+ return currentItem .folderName
33073229 else :
33083230 # TODO need debug msg?
33093231 return False
@@ -3516,7 +3438,7 @@ def tableWidgetInboxItemClicked(self):
35163438 refresh = False
35173439 for row in queryreturn :
35183440 message , read = row
3519- if folder == 'inbox ' and read == 0 :
3441+ if folder != 'sent ' and read == 0 :
35203442 markread = sqlQuery (
35213443 '''UPDATE inbox SET read = 1 WHERE msgid = ?''' , msgid )
35223444 refresh = True
0 commit comments