rm backup
[retroconv] / main.py
diff --git a/main.py b/main.py
index aa102aa..46a7a6b 100644 (file)
--- a/main.py
+++ b/main.py
@@ -1,15 +1,19 @@
 import sys
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
-from csv_service import csvServ
 from models import *
-#from windows import *
 from GUI.main_window import *
 from GUI.inbox_window import *
 from GUI.message_window import *
 from GUI.sent_window import *
-#
-msgs=csvServ("sms.csv", "sent.csv")
+from csv_service import *
+from notification_service import Notifier
+#import gtk
+"""
+#from windows import *
+
+
+"""
 
 def showInboxMessages():
        #ui.stackedWidget.setCurrentIndex(1)
@@ -22,7 +26,7 @@ def showSentMessages():
 def showMsg():
        #ui.stackedWidget.setCurrentIndex(2)
        msg = msgs.getMsg(inboxWindow.listView.currentIndex().row())
-       print msg.getMsgText()
+       #print msg.getMsgText()
        inboxMsgWindow.msg_text.setText(msg.getMsgText())
        inboxMsgWindow.msg_address.setText(msg.getSenderName())
        inboxMsgWindow.msg_date.setText(msg.getDate())
@@ -80,6 +84,8 @@ def populateSent():
        #for x in msgs.sentLst:
                #print x.getRecName()
        
+msgs=csvServ()
+notifier = Notifier()
 
 def init():
        ################## Connect SIGNALS #######################
@@ -88,39 +94,138 @@ def init():
        QObject.connect(mainWindow.sent_button, SIGNAL("clicked()"),showSentMessages)
        QObject.connect(inboxWindow.listView, SIGNAL("clicked(QModelIndex)"),showMsg)
        QObject.connect(sentWindow.listView, SIGNAL("clicked(QModelIndex)"),showSentMsg)
+       QObject.connect(mainWindow.actionImport, SIGNAL("triggered()"),showInboxDialog)
+       QObject.connect(mainWindow.actionImport_Sent, SIGNAL("triggered()"),showSentDialog)
+       QObject.connect(inboxDialog, SIGNAL("fileSelected(QString)"), importInbox)
+       QObject.connect(sentDialog, SIGNAL("fileSelected(QString)"), importSent)
+       
+       #QObject.connect(dialog, SIGNAL("fileSelected(QString)"), importInboxFile)
         #QObject.connect(ui.msg_back, SIGNAL("clicked()"),showInboxMessages)
         #QObject.connect(ui.sent_msg_back, SIGNAL("clicked()"),showSentMessages)
         #QObject.connect(ui.sentView, SIGNAL("clicked(QModelIndex)"),showSentMsg)
         
-        ############################################################
+        ###########################################################
+        
+        ###########################################################
+        
         
-        ################# Other Init functions #####################
         
-       populateInbox()
-       populateSent()
+        ###########################################################
+        
+        ################ Other Init functions #####################
+        
+        
+        fetch = False
+        
+        if msgs.hasImportedSent():
+               fetch = True
+               msgs.fetchSent()
+               populateSent()
+        
+        if msgs.hasImportedInbox():
+               fetch = True
+               msgs.fetchInbox()
+               populateInbox()
+               
+       if fetch:
+               msgs.fetchContactsInfo()
+       
        
        ###########################################################
 
+#def showImportInboxFileDialog():
+       #name = QFileDialog.getOpenFileName(None, "Open Image", "/home/user/", "Image Files (*.png *.jpg *.bmp)");
+       #chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
+
+
+def importInbox(path):
+       if msgs.importInbox(path):
+               notifier.requestPatience()
+               
+               msgs.fetchContactsInfo()
+               populateInbox()
+               
+               notifier.showSuccess(len(msgs.recvLst))
+       else:
+               notifier.showFailure()
+               
+def importSent(path):
+       if msgs.importSent(path):
+               notifier.requestPatience()
+               
+               msgs.fetchContactsInfo()
+               populateSent()
+               
+               notifier.showSuccess(len(msgs.sentLst))
+       else:
+               notifier.showFailure()
+               
+       
+def showInboxDialog():
+       if not msgs.hasImportedInbox() :
+                inboxDialog.open()
+       else:
+               res = QMessageBox.question(mainWindow, "Retro Conversations",
+                                "This will overwrite previously imported Inbox SMS. Proceed?", QMessageBox.Yes | QMessageBox.No);
+                                
+                if res == QMessageBox.Yes:
+                       inboxDialog.open()
+               
+def showSentDialog():
+       if not msgs.hasImportedSent():
+                sentDialog.open()
+       else:
+               res = QMessageBox.question(mainWindow, "Retro Conversations",
+                                "This will overwrite previously imported Sent SMS. Proceed?", QMessageBox.Yes | QMessageBox.No);
+                                
+                if res == QMessageBox.Yes:
+                       sentDialog.open()
+
 if __name__ == '__main__':
        app = QApplication(sys.argv)
        #MainWindow = QtGui.QMainWindow()
        #ui = Ui_MainWindow()
        #ui.setupUi(MainWindow)
        #MainWindow.show()
-
+       
        ####### Initialization #########
+       
        mainWindow = Ui_MainWindow()
        inboxWindow = Ui_InboxWindow(mainWindow)
        sentWindow = Ui_SentWindow(mainWindow)
        inboxMsgWindow = Ui_MessageWindow(inboxWindow)
        sentMsgWindow = Ui_MessageWindow(sentWindow)
+       
+       
+       
+       inboxDialog = QFileDialog(mainWindow);
+       inboxDialog.setFilter("Recieved SMS CSV Files (*.csv)");
+       inboxDialog.setViewMode(QFileDialog.List);
+       
+       sentDialog = QFileDialog(mainWindow);
+       sentDialog.setFilter("Sent SMS CSV Files (*.csv)");
+       sentDialog.setViewMode(QFileDialog.List);
+
+       
+       
+       
+       
        #mainWindow=QMainWindow()
        init()
-
+       
        ################################
 
 
        mainWindow.show()
+
+
+       ################################
+
+       #win = QMainWindow()
+       #win.show()
+
+       #name = QFileDialog.getOpenFileName(None,"Open Image", "/home/user/", "Image Files (*.png *.jpg *.bmp)");
+       
        sys.exit(app.exec_())