1b9dfddacbafd168e6adbc9688bf68f030208a7a
[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                 print "Inbox is already Imported"
169                 
170 def showSentDialog():
171         if not msgs.hasImportedSent():
172                  sentDialog.open()
173         else:
174                 print "Sent is already Imported"
175
176 if __name__ == '__main__':
177         app = QApplication(sys.argv)
178         #MainWindow = QtGui.QMainWindow()
179         #ui = Ui_MainWindow()
180         #ui.setupUi(MainWindow)
181         #MainWindow.show()
182         
183         ####### Initialization #########
184         
185         mainWindow = Ui_MainWindow()
186         inboxWindow = Ui_InboxWindow(mainWindow)
187         sentWindow = Ui_SentWindow(mainWindow)
188         inboxMsgWindow = Ui_MessageWindow(inboxWindow)
189         sentMsgWindow = Ui_MessageWindow(sentWindow)
190         
191         
192         
193         inboxDialog = QFileDialog(mainWindow);
194         inboxDialog.setFilter("Recieved SMS CSV Files (*.csv)");
195         inboxDialog.setViewMode(QFileDialog.List);
196         
197         sentDialog = QFileDialog(mainWindow);
198         sentDialog.setFilter("Sent SMS CSV Files (*.csv)");
199         sentDialog.setViewMode(QFileDialog.List);
200
201         
202         
203         
204         
205         #mainWindow=QMainWindow()
206         init()
207         
208         ################################
209
210
211         mainWindow.show()
212
213
214         ################################
215
216         #win = QMainWindow()
217         #win.show()
218
219         #name = QFileDialog.getOpenFileName(None,"Open Image", "/home/user/", "Image Files (*.png *.jpg *.bmp)");
220         
221         sys.exit(app.exec_())
222
223
224
225