Updated packaging for new 0.0.2 release.
[qwerkisync] / Windows / TypesWindow.cpp
1 /*
2  * Copyright (C) 2011, Jamie Thompson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18
19 #include "TypesWindow.h"
20 #include "DirectoryWindow.h"
21
22 #include <QtGui>
23
24 using namespace Windows;
25
26 TypesWindow::TypesWindow(Settings& settings, QWidget *parent) :
27         BaseWindow(settings, parent)
28 {
29         CreateContents();
30 }
31
32 void TypesWindow::CreateContents()
33 {
34         switch(CurrentSettings().AppMode())
35         {
36                 case Settings::APPMODE_GUI:
37                 {
38                         QWidget *layoutWidget = new QWidget(centralWidget());
39                         layoutWidget->setGeometry(QRect(0, 0, 801, 251));
40
41                         QGridLayout *layout = new QGridLayout(layoutWidget);
42                         {
43                                 layout->setSizeConstraint(QLayout::SetMaximumSize);
44                                 layout->setContentsMargins(0, 0, 0, 0);
45
46                                 // Spacers
47                                 {
48                                         // Vertical 1
49                                         layout->addItem(
50                                                 new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding),
51                                                 6., 2, 1, 1);
52
53                                         // Vertical 2
54                                         layout->addItem(
55                                                 new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding),
56                                                 0, 2, 1, 1);
57
58                                         // Horzontal 1
59                                         layout->addItem(
60                                                 new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum),
61                                                 0, 4, 1, 1);
62
63                                         // Horizontal 2
64                                         layout->addItem(
65                                                 new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum),
66                                                 0, 0, 1, 1);
67                                 }
68
69                                 // Set up columns
70                                 layout->setColumnStretch(0, 3);
71                                 layout->setColumnStretch(1, 1);
72                                 layout->setColumnStretch(2, 1);
73                                 layout->setColumnStretch(3, 1);
74                                 layout->setColumnStretch(4, 4);
75
76                                 int row = 1;
77
78                                 // Begin Headings
79                                 {
80                                         QLabel *lblSent = new QLabel();
81                                         lblSent->setText(tr("Sent"));
82                                         lblSent->setAlignment(Qt::AlignCenter);
83                                         layout->addWidget(lblSent, row, 2, 1, 1);
84                                 }
85                                 {
86                                         QLabel  *lblReceived = new QLabel();
87                                         lblReceived->setText(tr("Recieved"));
88                                         lblReceived->setAlignment(Qt::AlignCenter);
89                                         layout->addWidget(lblReceived, row, 3, 1, 1);
90                                 }
91                                 ++row;
92                                 // End Headings
93
94                                 QSizePolicy sizePolicyForCheckBoxes(QSizePolicy::Minimum, QSizePolicy::Minimum);
95                                 sizePolicyForCheckBoxes.setHorizontalStretch(0);
96                                 sizePolicyForCheckBoxes.setVerticalStretch(0);
97                                 sizePolicyForCheckBoxes.setHeightForWidth(false);
98
99                                 // Calls
100                                 {
101                                         QLabel *lblCalls = new QLabel();
102                                         lblCalls->setText(tr("Calls"));
103                                         lblCalls->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
104                                         layout->addWidget(lblCalls, row, 1, 1, 1);
105                                 }
106                                 {
107                                         cbMadeCalls = new QCheckBox();
108                                         //cbMadeCalls->setEnabled(false);
109                                         cbMadeCalls->setSizePolicy(sizePolicyForCheckBoxes);
110                                         cbMadeCalls->setMaximumSize(QSize(70, 64));
111                                         layout->addWidget(cbMadeCalls, row, 2, 1, 1);
112                                 }
113                                 {
114                                         cbRecvCalls = new QCheckBox();
115                                         //cbRecvCalls->setEnabled(false);
116                                         cbRecvCalls->setSizePolicy(sizePolicyForCheckBoxes);
117                                         cbRecvCalls->setMaximumSize(QSize(70, 64));
118                                         layout->addWidget(cbRecvCalls, row, 3, 1, 1);
119                                 }
120                                 ++row;
121                                 // End Calls
122
123                                 // SMS
124                                 {
125                                         QLabel *lblSMS = new QLabel();
126                                         lblSMS->setText(tr("SMS"));
127                                         lblSMS->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
128                                         layout->addWidget(lblSMS, row, 1, 1, 1);
129                                 }
130                                 {
131                                         cbSentSMS = new QCheckBox();
132                                         cbSentSMS->setSizePolicy(sizePolicyForCheckBoxes);
133                                         cbSentSMS->setMaximumSize(QSize(70, 64));
134                                         layout->addWidget(cbSentSMS, row, 2, 1, 1);
135                                 }
136                                 {
137                                         cbRecvSMS = new QCheckBox();
138                                         cbRecvSMS->setSizePolicy(sizePolicyForCheckBoxes);
139                                         cbRecvSMS->setMaximumSize(QSize(70, 64));
140                                         layout->addWidget(cbRecvSMS, row, 3, 1, 1);
141                                 }
142                                 ++row;
143                                 // End SMS
144
145                                 // MMS
146                                 {
147                                         QLabel  *lblMMS = new QLabel();
148                                         lblMMS->setText(tr("MMS"));
149                                         lblMMS->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
150                                         layout->addWidget(lblMMS, row, 1, 1, 1);
151                                 }
152                                 {
153                                         cbSentMMS = new QCheckBox();
154                                         cbSentMMS->setEnabled(false);
155                                         cbSentMMS->setSizePolicy(sizePolicyForCheckBoxes);
156                                         cbSentMMS->setMaximumSize(QSize(70, 64));
157                                         layout->addWidget(cbSentMMS, row, 2, 1, 1);
158                                 }
159                                 {
160                                         cbRecvMMS = new QCheckBox();
161                                         cbRecvMMS->setEnabled(false);
162                                         cbRecvMMS->setSizePolicy(sizePolicyForCheckBoxes);
163                                         cbRecvMMS->setMaximumSize(QSize(70, 64));
164                                         layout->addWidget(cbRecvMMS, row, 3, 1, 1);
165                                 }
166                                 ++row;
167                                 // End MMS
168
169                                 // Chat
170                                 {
171                                         QLabel  *lblChat = new QLabel();
172                                         lblChat->setText(tr("Chat"));
173                                         lblChat->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
174                                         layout->addWidget(lblChat, row, 1, 1, 1);
175                                 }
176                                 {
177                                         cbSentChat = new QCheckBox();
178                                         cbSentChat->setEnabled(false);
179                                         cbSentChat->setSizePolicy(sizePolicyForCheckBoxes);
180                                         cbSentChat->setMaximumSize(QSize(70, 64));
181                                         layout->addWidget(cbSentChat, row, 2, 1, 1);
182                                 }
183                                 {
184                                         cbRecvChat = new QCheckBox();
185                                         cbRecvChat->setEnabled(false);
186                                         cbRecvChat->setSizePolicy(sizePolicyForCheckBoxes);
187                                         cbRecvChat->setMaximumSize(QSize(70, 64));
188                                         layout->addWidget(cbRecvChat, row, 3, 1, 1);
189                                 }
190                                 ++row;
191                                 // End Chat
192
193                                 // Continue button
194                                 {
195                                         btnContinue = new QPushButton(centralWidget());
196                                         btnContinue->setText(tr("Continue..."));
197                                         {
198                                                 QSizePolicy sizePolicyForContinueButton(QSizePolicy::Fixed, QSizePolicy::Fixed);
199                                                 sizePolicyForContinueButton.setHorizontalStretch(0);
200                                                 sizePolicyForContinueButton.setVerticalStretch(0);
201                                                 sizePolicyForContinueButton.setHeightForWidth(true);
202                                                 btnContinue->setSizePolicy(sizePolicyForContinueButton);
203                                         }
204                                         QObject::connect(btnContinue, SIGNAL(clicked()), this, SLOT(Continue()));
205                                 }
206
207                                 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(OrientationChanged()));
208                                 OrientationChanged();
209
210                                 centralWidget()->setLayout(layout);
211                         }
212
213                         break;
214                 }
215
216                 case Settings::APPMODE_CONSOLE:
217                 {
218                         // Process args.
219
220                         Advance();
221                         break;
222                 }
223         }
224 }
225
226 void TypesWindow::OrientationChanged()
227 {
228         QRect screenGeometry = QApplication::desktop()->screenGeometry();
229         // Landscape
230         if (screenGeometry.width() > screenGeometry.height())
231                 btnContinue->setGeometry(QRect(610, 340, 184, 80));
232         // Portrait
233         else
234                 btnContinue->setGeometry(QRect(290, 655, 184, 80));
235 }
236
237 void TypesWindow::Continue()
238 {
239         CurrentSettings().setShouldProcess(Settings::OUTGOING, EventTypes::EVENT_TYPE_CALL, cbMadeCalls->checkState() == Qt::Checked);
240         CurrentSettings().setShouldProcess(Settings::OUTGOING, EventTypes::EVENT_TYPE_SMS, cbSentSMS->checkState() == Qt::Checked);
241         CurrentSettings().setShouldProcess(Settings::OUTGOING, EventTypes::EVENT_TYPE_MMS, cbSentMMS->checkState() == Qt::Checked);
242         CurrentSettings().setShouldProcess(Settings::OUTGOING, EventTypes::EVENT_TYPE_CHAT, cbSentChat->checkState() == Qt::Checked);
243         CurrentSettings().setShouldProcess(Settings::INCOMING, EventTypes::EVENT_TYPE_CALL, cbRecvCalls->checkState() == Qt::Checked);
244         CurrentSettings().setShouldProcess(Settings::INCOMING, EventTypes::EVENT_TYPE_SMS, cbRecvSMS->checkState() == Qt::Checked);
245         CurrentSettings().setShouldProcess(Settings::INCOMING, EventTypes::EVENT_TYPE_MMS, cbRecvMMS->checkState() == Qt::Checked);
246         CurrentSettings().setShouldProcess(Settings::INCOMING, EventTypes::EVENT_TYPE_CHAT, cbRecvChat->checkState() == Qt::Checked);
247
248         if(CurrentSettings().anyToProcess())
249                 Advance();
250         else
251                 QMessageBox::critical(this, tr("Excuse me"), tr("You must select at least one type of data to process."));
252 }
253
254 void TypesWindow::Advance()
255 {
256         QWidget* next = new DirectoryWindow(CurrentSettings(), this);
257         next->show();
258 }