1 #include "mainform.h"
\r
2 #include "ui_mainform.h"
\r
4 MainForm::MainForm(QWidget *parent) :
\r
9 settings = new QSettings(WILLEM_LIU, EASY_LIST);
\r
11 /* Make a call every x milliseconds */
\r
12 timer = new QTimer(this);
\r
13 connect(timer, SIGNAL(timeout()), this, SLOT(Keep_backlight_on()));
\r
15 requestWebpage = new RequestWebpage(this);
\r
16 connect(requestWebpage, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotSyncList(QNetworkReply*)));
\r
19 connect(SystemSettings::getInstance(), SIGNAL(signalKeyboardClosed(bool)), this, SLOT(keyboardClosed(bool)));
\r
21 ui->actionAuto_Orientation->setChecked(settings->value(AUTO_ORIENTATION).toBool());
\r
22 on_actionAuto_Orientation_triggered();
\r
24 ui->actionSort_A_Z->setChecked(settings->value(SORT_A_Z).toBool());
\r
25 on_actionSort_A_Z_triggered();
\r
27 // Set a default value for CHECKED_ITEMS_TO_BOTTOM
\r
28 if(settings->contains(CHECKED_ITEMS_TO_BOTTOM) == false)
\r
30 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, false);
\r
32 ui->actionChecked_bottom->setChecked(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool());
\r
33 on_actionChecked_bottom_triggered();
\r
35 // Set a default value for CHECKED_BACKLIGHT
\r
36 if(settings->contains(CHECKED_BACKLIGHT) == false)
\r
38 settings->setValue(CHECKED_BACKLIGHT, false);
\r
40 ui->actionKeep_backlight_on->setChecked(settings->value(CHECKED_BACKLIGHT).toBool());
\r
41 on_actionKeep_backlight_on_triggered();
\r
43 // Create a default for landscape mode.
\r
44 landscape = settings->value(LANDSCAPE).toBool();
\r
45 // If LANDSCAPE exists in QSettings.
\r
46 if(settings->contains(LANDSCAPE))
\r
48 // We use the LANDSCAPE value in the QSettings.
\r
49 landscape = settings->value(LANDSCAPE).toBool();
\r
53 // Otherwise we set our default into the QSettings.
\r
54 settings->setValue(LANDSCAPE, landscape);
\r
56 // If keyboard is opened at start. We do landscape mode.
\r
57 // Otherwise we do what's read from the QSettings.
\r
58 if(ui->actionAuto_Orientation->isChecked() == false)
\r
60 if(SystemSettings::getInstance()->getKeyboardClosed() == false)
\r
62 setLandscapeMode(true);
\r
66 setLandscapeMode(landscape);
\r
70 // Populate the QStackedWidget. ListForm is set as the current widget.
\r
71 listForm = new ListForm(this);
\r
72 editForm = new EditForm(this);
\r
73 chooseListForm = new ChooseListForm(this);
\r
74 settingsForm = new SettingsForm(this);
\r
76 connect(listForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
77 connect(listForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
79 connect(editForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
80 connect(editForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
82 connect(chooseListForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
83 connect(chooseListForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
85 connect(settingsForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
86 connect(settingsForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
88 ui->stackedWidget->addWidget(listForm);
\r
89 ui->stackedWidget->addWidget(editForm);
\r
90 ui->stackedWidget->addWidget(chooseListForm);
\r
91 ui->stackedWidget->addWidget(settingsForm);
\r
92 ui->stackedWidget->setCurrentWidget(listForm);
\r
95 MainForm::~MainForm()
\r
100 void MainForm::stateOutFinished()
\r
102 qDebug() << "Show new widget" << newIndex;
\r
103 ui->stackedWidget->setCurrentIndex(newIndex);
\r
104 SlideWidget * newWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
105 newWidget->move(0, -newWidget->height());
\r
106 newWidget->setStateIn();
\r
107 newWidget->shown();
\r
110 void MainForm::changeWidget(int step)
\r
112 SlideWidget * currentWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
113 currentWidget->initStates();
\r
114 int currentIndex = ui->stackedWidget->indexOf(currentWidget);
\r
115 // Because all widgets are started with StateOut as initial state, we
\r
116 // need to reset the current widget to StateIn. The view is showing the
\r
117 // current widget at the place of its StateIn position. But the state
\r
118 // is never set to StateIn.
\r
119 currentWidget->setStateIn();
\r
120 qDebug() << "Current widget index" << currentIndex;
\r
122 currentWidget->setStateOut();
\r
123 qDebug() << "New widget index" << newIndex;
\r
126 void MainForm::keyboardClosed(bool closed)
\r
128 // When keyboard is opened.
\r
129 if(ui->actionAuto_Orientation->isChecked() == false)
\r
131 if(closed == false)
\r
133 setLandscapeMode(true);
\r
137 setLandscapeMode(landscape);
\r
142 void MainForm::setLandscapeMode(bool landscape)
\r
146 tempLandscapeMode = true;
\r
147 qDebug() << LANDSCAPE;
\r
148 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
\r
149 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
150 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
\r
151 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
156 tempLandscapeMode = false;
\r
157 qDebug() << PORTRAIT;
\r
158 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
\r
159 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
160 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
\r
161 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
166 void MainForm::on_actionRotate_triggered()
\r
168 qDebug() << "Rotate";
\r
170 landscape = (width() < height());
\r
171 settings->setValue(LANDSCAPE, landscape);
\r
172 ui->actionAuto_Orientation->setChecked(false);
\r
173 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
174 setLandscapeMode(landscape);
\r
177 void MainForm::on_actionAbout_triggered()
\r
179 qDebug() << "About";
\r
181 aboutText.append("<html><body>");
\r
182 aboutText.append("EasyList (c) 2010-");
\r
183 aboutText.append(QDate::currentDate().toString("yyyy"));
\r
184 aboutText.append("<br><br>");
\r
185 aboutText.append("Created by Willem Liu.<br>");
\r
186 aboutText.append("Thanks to Ade.<br>");
\r
187 aboutText.append("Created with QtCreator.<br><br>");
\r
188 aboutText.append("Please <a href='http://www.willemliu.nl/donate'>donate</a> any amount you deem this app is worthy to keep me going on.<br><br>");
\r
189 aboutText.append("</body></html>");
\r
190 QMessageBox::about(this, "EasyList", aboutText);
\r
193 void MainForm::on_actionChecked_bottom_triggered()
\r
195 bool sortToBottom = ui->actionChecked_bottom->isChecked();
\r
196 qDebug() << "Checked Bottom" << sortToBottom;
\r
197 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, sortToBottom);
\r
198 MyCheckBoxContainer::getInstance()->setSortCheckedToBottom(sortToBottom);
\r
201 void MainForm::closeEvent(QCloseEvent *event)
\r
203 settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());
\r
204 SystemSettings::getInstance()->saveCurrentList();
\r
208 void MainForm::on_actionAuto_Orientation_triggered()
\r
210 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
211 qDebug() << "Auto orientation" << ui->actionAuto_Orientation->isChecked();
\r
212 if(ui->actionAuto_Orientation->isChecked())
\r
214 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
\r
215 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
216 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
217 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
\r
222 setLandscapeMode(landscape);
\r
226 void MainForm::on_actionSort_A_Z_triggered()
\r
228 settings->setValue(SORT_A_Z, ui->actionSort_A_Z->isChecked());
\r
229 MyCheckBoxContainer::getInstance()->setSortAlphabetically(ui->actionSort_A_Z->isChecked());
\r
232 void MainForm::on_actionLists_triggered()
\r
234 listForm->saveList();
\r
238 void MainForm::on_actionSync_triggered()
\r
240 int res = QMessageBox::warning(this, "Synchronize list", "If you haven't saved your current list under a list name other than SyncList then it will be overwritten by the items on the website.", QMessageBox::Ok, QMessageBox::Cancel);
\r
242 if(res == QMessageBox::Ok)
\r
244 QString username = settings->value(USERNAME, "").toString();
\r
245 QString password = settings->value(PASSWORD, "").toString();
\r
246 QString url = settings->value(SYNC_URL, DEFAULT_SYNC_URL).toString();
\r
247 url.append("?username=" + username);
\r
248 url.append("&password=" + password);
\r
250 requestWebpage->post(url,settings->value(LIST_TEXT,"").toString().toUtf8());
\r
251 //requestWebpage->fetch(url);
\r
255 void MainForm::slotSyncList(QNetworkReply* pReply)
\r
257 settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());
\r
258 SystemSettings::getInstance()->saveCurrentList();
\r
259 QByteArray data=pReply->readAll();
\r
260 QString list = QString::fromUtf8(data);
\r
261 settings->setValue(LIST_TEXT, list);
\r
262 settings->setValue(SELECTED_LIST_NAME, SYNC_LIST_NAME);
\r
263 settings->setValue(SYNC_LIST_NAME, settings->value(LIST_TEXT, ""));
\r
264 QStringList listNames = settings->value(LIST_NAMES, "").toStringList();
\r
265 if(listNames.contains(SYNC_LIST_NAME) == false)
\r
267 listNames.append(SYNC_LIST_NAME);
\r
269 settings->setValue(LIST_NAMES, QVariant(listNames));
\r
271 pReply->deleteLater();
\r
274 void MainForm::on_actionSetting_triggered()
\r
279 void MainForm::on_actionKeep_backlight_on_triggered()
\r
281 bool setBacklight = ui->actionKeep_backlight_on->isChecked();
\r
284 if(timer->isActive() == false)
\r
286 timer->start(5000);
\r
291 qDebug() << "Backlight: " << setBacklight;
\r
294 qDebug() << "Checked Backlight" << setBacklight;
\r
295 settings->setValue(CHECKED_BACKLIGHT, setBacklight);
\r
298 void MainForm::Keep_backlight_on()
\r
300 bool setBacklight = ui->actionKeep_backlight_on->isChecked();
\r
303 qDebug() << "Backlight: " << setBacklight;
\r
304 QString strUnlock = "dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_display_blanking_pause";
\r
305 QProcess::startDetached(strUnlock);
\r