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 requestWebpage = new RequestWebpage(this);
\r
12 connect(requestWebpage, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotSyncList(QNetworkReply*)));
\r
15 connect(SystemSettings::getInstance(), SIGNAL(signalKeyboardClosed(bool)), this, SLOT(keyboardClosed(bool)));
\r
17 ui->actionAuto_Orientation->setChecked(settings->value(AUTO_ORIENTATION).toBool());
\r
18 on_actionAuto_Orientation_triggered();
\r
20 ui->actionSort_A_Z->setChecked(settings->value(SORT_A_Z).toBool());
\r
21 on_actionSort_A_Z_triggered();
\r
23 // Set a default value for CHECKED_ITEMS_TO_BOTTOM
\r
24 if(settings->contains(CHECKED_ITEMS_TO_BOTTOM) == false)
\r
26 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, false);
\r
28 ui->actionChecked_bottom->setChecked(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool());
\r
29 on_actionChecked_bottom_triggered();
\r
31 // Create a default for landscape mode.
\r
32 landscape = settings->value(LANDSCAPE).toBool();
\r
33 // If LANDSCAPE exists in QSettings.
\r
34 if(settings->contains(LANDSCAPE))
\r
36 // We use the LANDSCAPE value in the QSettings.
\r
37 landscape = settings->value(LANDSCAPE).toBool();
\r
41 // Otherwise we set our default into the QSettings.
\r
42 settings->setValue(LANDSCAPE, landscape);
\r
44 // If keyboard is opened at start. We do landscape mode.
\r
45 // Otherwise we do what's read from the QSettings.
\r
46 if(ui->actionAuto_Orientation->isChecked() == false)
\r
48 if(SystemSettings::getInstance()->getKeyboardClosed() == false)
\r
50 setLandscapeMode(true);
\r
54 setLandscapeMode(landscape);
\r
58 // Populate the QStackedWidget. ListForm is set as the current widget.
\r
59 listForm = new ListForm(this);
\r
60 editForm = new EditForm(this);
\r
61 chooseListForm = new ChooseListForm(this);
\r
62 settingsForm = new SettingsForm(this);
\r
64 connect(listForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
65 connect(listForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
67 connect(editForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
68 connect(editForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
70 connect(chooseListForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
71 connect(chooseListForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
73 connect(settingsForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
74 connect(settingsForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
76 ui->stackedWidget->addWidget(listForm);
\r
77 ui->stackedWidget->addWidget(editForm);
\r
78 ui->stackedWidget->addWidget(chooseListForm);
\r
79 ui->stackedWidget->addWidget(settingsForm);
\r
80 ui->stackedWidget->setCurrentWidget(listForm);
\r
83 MainForm::~MainForm()
\r
88 void MainForm::stateOutFinished()
\r
90 qDebug() << "Show new widget" << newIndex;
\r
91 ui->stackedWidget->setCurrentIndex(newIndex);
\r
92 SlideWidget * newWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
93 newWidget->move(0, -newWidget->height());
\r
94 newWidget->setStateIn();
\r
98 void MainForm::changeWidget(int step)
\r
100 SlideWidget * currentWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
101 currentWidget->initStates();
\r
102 int currentIndex = ui->stackedWidget->indexOf(currentWidget);
\r
103 // Because all widgets are started with StateOut as initial state, we
\r
104 // need to reset the current widget to StateIn. The view is showing the
\r
105 // current widget at the place of its StateIn position. But the state
\r
106 // is never set to StateIn.
\r
107 currentWidget->setStateIn();
\r
108 qDebug() << "Current widget index" << currentIndex;
\r
110 currentWidget->setStateOut();
\r
111 qDebug() << "New widget index" << newIndex;
\r
114 void MainForm::keyboardClosed(bool closed)
\r
116 // When keyboard is opened.
\r
117 if(ui->actionAuto_Orientation->isChecked() == false)
\r
119 if(closed == false)
\r
121 setLandscapeMode(true);
\r
125 setLandscapeMode(landscape);
\r
130 void MainForm::setLandscapeMode(bool landscape)
\r
134 tempLandscapeMode = true;
\r
135 qDebug() << LANDSCAPE;
\r
136 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
\r
137 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
138 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
\r
139 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
144 tempLandscapeMode = false;
\r
145 qDebug() << PORTRAIT;
\r
146 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
\r
147 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
148 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
\r
149 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
154 void MainForm::on_actionRotate_triggered()
\r
156 qDebug() << "Rotate";
\r
158 landscape = (width() < height());
\r
159 settings->setValue(LANDSCAPE, landscape);
\r
160 ui->actionAuto_Orientation->setChecked(false);
\r
161 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
162 setLandscapeMode(landscape);
\r
165 void MainForm::on_actionAbout_triggered()
\r
167 qDebug() << "About";
\r
169 aboutText.append("<html><body>");
\r
170 aboutText.append("EasyList (c) 2010-");
\r
171 aboutText.append(QDate::currentDate().toString("yyyy"));
\r
172 aboutText.append("<br><br>");
\r
173 aboutText.append("Created by Willem Liu.<br>");
\r
174 aboutText.append("Created with QtCreator.<br><br>");
\r
175 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
176 aboutText.append("</body></html>");
\r
177 QMessageBox::about(this, "EasyList", aboutText);
\r
180 void MainForm::on_actionChecked_bottom_triggered()
\r
182 bool sortToBottom = ui->actionChecked_bottom->isChecked();
\r
183 qDebug() << "Checked Bottom" << sortToBottom;
\r
184 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, sortToBottom);
\r
185 MyCheckBoxContainer::getInstance()->setSortCheckedToBottom(sortToBottom);
\r
188 void MainForm::closeEvent(QCloseEvent *event)
\r
190 settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());
\r
191 SystemSettings::getInstance()->saveCurrentList();
\r
195 void MainForm::on_actionAuto_Orientation_triggered()
\r
197 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
198 qDebug() << "Auto orientation" << ui->actionAuto_Orientation->isChecked();
\r
199 if(ui->actionAuto_Orientation->isChecked())
\r
201 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
\r
202 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
203 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
204 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
\r
209 setLandscapeMode(landscape);
\r
213 void MainForm::on_actionSort_A_Z_triggered()
\r
215 settings->setValue(SORT_A_Z, ui->actionSort_A_Z->isChecked());
\r
216 MyCheckBoxContainer::getInstance()->setSortAlphabetically(ui->actionSort_A_Z->isChecked());
\r
219 void MainForm::on_actionLists_triggered()
\r
221 listForm->saveList();
\r
225 void MainForm::on_actionSync_triggered()
\r
227 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
229 if(res == QMessageBox::Ok)
\r
231 QString username = settings->value(USERNAME, "").toString();
\r
232 QString password = settings->value(PASSWORD, "").toString();
\r
233 QString url = settings->value(SYNC_URL, DEFAULT_SYNC_URL).toString();
\r
234 url.append("?username=" + username);
\r
235 url.append("&password=" + password);
\r
237 requestWebpage->post(url,settings->value(LIST_TEXT,"").toString().toUtf8());
\r
238 //requestWebpage->fetch(url);
\r
242 void MainForm::slotSyncList(QNetworkReply* pReply)
\r
244 settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());
\r
245 SystemSettings::getInstance()->saveCurrentList();
\r
246 QByteArray data=pReply->readAll();
\r
247 QString list = QString::fromUtf8(data);
\r
248 settings->setValue(LIST_TEXT, list);
\r
249 settings->setValue(SELECTED_LIST_NAME, SYNC_LIST_NAME);
\r
250 settings->setValue(SYNC_LIST_NAME, settings->value(LIST_TEXT, ""));
\r
251 QStringList listNames = settings->value(LIST_NAMES, "").toStringList();
\r
252 if(listNames.contains(SYNC_LIST_NAME) == false)
\r
254 listNames.append(SYNC_LIST_NAME);
\r
256 settings->setValue(LIST_NAMES, QVariant(listNames));
\r
258 pReply->deleteLater();
\r
261 void MainForm::on_actionSetting_triggered()
\r