prepare for packaging
[retroconv] / main.py
1 import sys
2 from PyQt4.QtCore import *
3 from PyQt4.QtGui import *
4 from models import *
5 from GUI.main_window import *
6 from GUI.inbox_window import *
7 from GUI.message_window import *
8 from GUI.sent_window import *
9 from csv_service import *
10 from notification_service import Notifier
11 #import gtk
12 """
13 #from windows import *
14
15
16 """
17
18 def showInboxMessages():
19         #ui.stackedWidget.setCurrentIndex(1)
20         inboxWindow.show()
21
22 def showSentMessages():
23         #ui.stackedWidget.setCurrentIndex(3)
24         sentWindow.show()
25         
26 def showMsg():
27         #ui.stackedWidget.setCurrentIndex(2)
28         msg = msgs.getMsg(inboxWindow.listView.currentIndex().row())
29         #print msg.getMsgText()
30         inboxMsgWindow.msg_text.setText(msg.getMsgText())
31         inboxMsgWindow.msg_address.setText(msg.getSenderName())
32         inboxMsgWindow.msg_date.setText(msg.getDate())
33         
34         #####################################
35         
36         
37         if msg.getImageData() == "":
38                 inboxMsgWindow.frame.setPixmap(QPixmap("graphics/contact_trans_120.png"))
39         else:
40         
41                 arr=QByteArray(msg.getImageData())
42                 img = QPixmap()
43                 img.loadFromData(arr)
44                 
45                 inboxMsgWindow.frame.setPixmap(img.scaled(120,120, Qt.KeepAspectRatioByExpanding))
46                 
47         inboxMsgWindow.show()
48
49
50 def showSentMsg():
51         #ui.stackedWidget.setCurrentIndex(4)
52         msg = msgs.getMsg(sentWindow.listView.currentIndex().row(), 1)
53         sentMsgWindow.msg_text.setText(msg.getMsgText())
54         sentMsgWindow.msg_address.setText(msg.getRecName())
55         sentMsgWindow.msg_date.setText(msg.getDate())
56         
57         #####################################
58         
59         if msg.getImageData() == "":
60                 sentMsgWindow.frame.setPixmap(QPixmap("graphics/contact_trans_120.png"))
61         else:
62                 arr=QByteArray(msg.getImageData())
63                 img = QPixmap()
64                 img.loadFromData(arr)
65                 
66                 sentMsgWindow.frame.setPixmap(img.scaled(120,120, Qt.KeepAspectRatioByExpanding))
67         
68         sentMsgWindow.show()
69         
70 def populateInbox():
71         #allSenders=msgs.getAllSenders()
72         #for x in allSenders:
73         
74         recvModel=RecvModel(msgs.recvLst)
75         inboxWindow.listView.setModel(recvModel)
76                 
77 def populateSent():
78         #allSenders=msgs.getAllSenders()
79         #for x in allSenders:
80         
81         sentModel=SentModel(msgs.sentLst)
82         sentWindow.listView.setModel(sentModel)
83         
84         #for x in msgs.sentLst:
85                 #print x.getRecName()
86         
87 msgs=csvServ()
88 notifier = Notifier()
89
90 def init():
91         ################## Connect SIGNALS #######################
92         
93         QObject.connect(mainWindow.inbox_button, SIGNAL("clicked()"), showInboxMessages)
94         QObject.connect(mainWindow.sent_button, SIGNAL("clicked()"),showSentMessages)
95         QObject.connect(inboxWindow.listView, SIGNAL("clicked(QModelIndex)"),showMsg)
96         QObject.connect(sentWindow.listView, SIGNAL("clicked(QModelIndex)"),showSentMsg)
97         QObject.connect(mainWindow.actionImport, SIGNAL("triggered()"),showInboxDialog)
98         QObject.connect(mainWindow.actionImport_Sent, SIGNAL("triggered()"),showSentDialog)
99         QObject.connect(inboxDialog, SIGNAL("fileSelected(QString)"), importInbox)
100         QObject.connect(sentDialog, SIGNAL("fileSelected(QString)"), importSent)
101         
102         #QObject.connect(dialog, SIGNAL("fileSelected(QString)"), importInboxFile)
103         #QObject.connect(ui.msg_back, SIGNAL("clicked()"),showInboxMessages)
104         #QObject.connect(ui.sent_msg_back, SIGNAL("clicked()"),showSentMessages)
105         #QObject.connect(ui.sentView, SIGNAL("clicked(QModelIndex)"),showSentMsg)
106         
107         ############################################################
108         
109         ############################################################
110         
111         
112         
113         ############################################################
114         
115         ################# Other Init functions #####################
116         
117         
118         fetch = False
119         
120         if msgs.hasImportedSent():
121                 fetch = True
122                 msgs.fetchSent()
123                 populateSent()
124         
125         if msgs.hasImportedInbox():
126                 fetch = True
127                 msgs.fetchInbox()
128                 populateInbox()
129                 
130         if fetch:
131                 msgs.fetchContactsInfo()
132         
133         
134         ###########################################################
135
136 #def showImportInboxFileDialog():
137         #name = QFileDialog.getOpenFileName(None, "Open Image", "/home/user/", "Image Files (*.png *.jpg *.bmp)");
138         #chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
139
140
141 def importInbox(path):
142         if msgs.importInbox(path):
143                 notifier.requestPatience()
144                 
145                 msgs.fetchContactsInfo()
146                 populateInbox()
147                 
148                 notifier.showSuccess(len(msgs.recvLst))
149         else:
150                 notifier.showFailure()
151                 
152 def importSent(path):
153         if msgs.importSent(path):
154                 notifier.requestPatience()
155                 
156                 msgs.fetchContactsInfo()
157                 populateSent()
158                 
159                 notifier.showSuccess(len(msgs.sentLst))
160         else:
161                 notifier.showFailure()
162                 
163         
164 def showInboxDialog():
165         if not msgs.hasImportedInbox() :
166                  inboxDialog.open()
167         else:
168                 res = QMessageBox.question(mainWindow, "Retro Conversations",
169                                 "This will overwrite previously imported Inbox SMS. Proceed?", QMessageBox.Yes | QMessageBox.No);
170                                 
171                 if res == QMessageBox.Yes:
172                         inboxDialog.open()
173                 
174 def showSentDialog():
175         if not msgs.hasImportedSent():
176                  sentDialog.open()
177         else:
178                 res = QMessageBox.question(mainWindow, "Retro Conversations",
179                                 "This will overwrite previously imported Sent SMS. Proceed?", QMessageBox.Yes | QMessageBox.No);
180                                 
181                 if res == QMessageBox.Yes:
182                         sentDialog.open()
183
184 if __name__ == '__main__':
185         app = QApplication(sys.argv)
186         #MainWindow = QtGui.QMainWindow()
187         #ui = Ui_MainWindow()
188         #ui.setupUi(MainWindow)
189         #MainWindow.show()
190         
191         ####### Initialization #########
192         
193         mainWindow = Ui_MainWindow()
194         inboxWindow = Ui_InboxWindow(mainWindow)
195         sentWindow = Ui_SentWindow(mainWindow)
196         inboxMsgWindow = Ui_MessageWindow(inboxWindow)
197         sentMsgWindow = Ui_MessageWindow(sentWindow)
198         
199         
200         
201         inboxDialog = QFileDialog(mainWindow);
202         inboxDialog.setFilter("Recieved SMS CSV Files (*.csv)");
203         inboxDialog.setViewMode(QFileDialog.List);
204         
205         sentDialog = QFileDialog(mainWindow);
206         sentDialog.setFilter("Sent SMS CSV Files (*.csv)");
207         sentDialog.setViewMode(QFileDialog.List);
208
209         
210         
211         
212         
213         #mainWindow=QMainWindow()
214         init()
215         
216         ################################
217
218
219         mainWindow.show()
220
221
222         ################################
223
224         #win = QMainWindow()
225         #win.show()
226
227         #name = QFileDialog.getOpenFileName(None,"Open Image", "/home/user/", "Image Files (*.png *.jpg *.bmp)");
228         
229         sys.exit(app.exec_())
230
231
232
233