2 * Copyright (c) 2010 Willem Liu
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
23 #include "mainwindow.h"
\r
24 #include "ui_mainwindow.h"
\r
25 #include "ui_listwindow.h"
\r
27 #define DBUS_KEYBOARD_SLIDE "/org/freedesktop/Hal/devices/platform_slide"
\r
31 * Settings are initialised here.
\r
32 * Landscape mode is set to true.
\r
33 * List window is loaded.
\r
35 * @param parent - The parent widget.
\r
37 MainWindow::MainWindow(QWidget *parent) :
\r
38 QMainWindow(parent),
\r
39 editUi(new Ui::EditWindow),
\r
40 listUi(new Ui::ListWindow)
\r
42 // Connect to DBUS of keyboard slider.
\r
43 QDBusConnection::systemBus().connect(QString("org.freedesktop.Hal"),
\r
44 DBUS_KEYBOARD_SLIDE,
\r
45 QString("org.freedesktop.Hal.Device"),
\r
46 QString("PropertyModified"),
\r
47 this, SLOT(slotKeyboardSlide()));
\r
48 // Initialise the settings.
\r
49 settings = new QSettings("WillemLiu", "easylist");
\r
50 // We always start in landscape mode.
\r
51 landscape = settings->value("Landscape").toBool();
\r
52 if(settings->contains("Landscape"))
\r
54 landscape = settings->value("Landscape").toBool();
\r
56 settings->setValue("Landscape", landscape);
\r
57 // If keyboard is opened at start.
\r
58 if(isKeyboardClosed() == false)
\r
62 setLandscapeMode(landscape);
\r
63 // Auto-detect portrait/landscape mode. Only works on top widget.
\r
64 // setAttribute(Qt::WA_Maemo5AutoOrientation, true);
\r
70 * User interface pointers are deleted here.
\r
74 MainWindow::~MainWindow()
\r
81 * Check the DBUS property to see if the keyboard is closed or opened.
\r
83 bool MainWindow::isKeyboardClosed()
\r
85 QDBusInterface propertyInterface("org.freedesktop.Hal",
\r
86 DBUS_KEYBOARD_SLIDE,
\r
87 "org.freedesktop.Hal.Device",
\r
88 QDBusConnection::systemBus());
\r
89 bool result = propertyInterface.call("GetProperty", "button.state.value").arguments().at(0).toBool();
\r
90 qDebug() << "Keyboard is closed:" << result;
\r
95 * Slot is called when a DBUS event has been received caused by opening/closing the keyboard.
\r
97 void MainWindow::slotKeyboardSlide()
\r
99 // When keyboard is opened.
\r
100 if(false == isKeyboardClosed())
\r
102 setLandscapeMode(true);
\r
106 setLandscapeMode(landscape);
\r
111 * Slot for action from Edit list button in de the list window.
\r
113 * @fn slotListWindowEdit
\r
115 void MainWindow::slotListWindowEdit()
\r
117 qDebug() << "Edit list";
\r
122 * Slot for action from Cancel button in de the edit window.
\r
124 * @fn slotEditWindowCancel
\r
126 void MainWindow::slotEditWindowCancel()
\r
128 qDebug() << "Cancel";
\r
133 * Slot for action from Save button in de the edit window.
\r
135 * @fn slotEditWindowSave
\r
137 void MainWindow::slotEditWindowSave()
\r
139 qDebug() << "Save";
\r
140 settings->setValue("ListText", editUi->textEdit->toPlainText());
\r
145 * Slot for action from Clear selected button in de the list window.
\r
147 * @fn slotListWindowClearSelected
\r
149 void MainWindow::slotListWindowClearSelected()
\r
151 qDebug() << "Clear selected";
\r
152 QString listText("");
\r
153 foreach(QCheckBox * cb, checkBoxes)
\r
156 if(cb->isChecked() == false)
\r
158 listText.append(cb->text());
\r
159 listText.append("\n");
\r
163 settings->setValue("ListText", listText);
\r
168 * Show the edit window.
\r
170 * @fn showEditWindow
\r
172 void MainWindow::showEditWindow()
\r
174 editUi->setupUi(this);
\r
175 editUi->textEdit->setText(settings->value("ListText").toString());
\r
176 connect(editUi->savePushButton, SIGNAL(clicked()), this, SLOT(slotEditWindowSave()));
\r
177 connect(editUi->cancelPushButton, SIGNAL(clicked()), this, SLOT(slotEditWindowCancel()));
\r
181 * Show the list window.
\r
183 * @fn showListWindow
\r
185 void MainWindow::showListWindow()
\r
187 listUi->setupUi(this);
\r
188 listUi->listVerticalLayout->setAlignment(Qt::AlignTop);
\r
190 connect(listUi->editListPushButton, SIGNAL(clicked()), this, SLOT(slotListWindowEdit()));
\r
191 connect(listUi->clearSelectedPushButton, SIGNAL(clicked()), this, SLOT(slotListWindowClearSelected()));
\r
192 connect(listUi->menuAbout, SIGNAL(triggered(QAction*)), this, SLOT(slotActionAbout(QAction*)));
\r
193 connect(listUi->menuRotate, SIGNAL(triggered(QAction*)), this, SLOT(slotActionRotate(QAction*)));
\r
197 * Generate the list of checkboxes. A pointer to such a checkbox will be stored
\r
198 * in a container for later use.
\r
202 void MainWindow::generateList()
\r
204 qDebug() << "Generate List";
\r
206 checkBoxes.clear();
\r
207 QString text = settings->value("ListText").toString();
\r
208 QStringList list = text.split("\n");
\r
210 foreach(QString item, list)
\r
212 if(item.length() > 0)
\r
214 QCheckBox * cb = new QCheckBox(item);
\r
215 checkBoxes.append(cb);
\r
216 listUi->listVerticalLayout->addWidget(cb);
\r
222 * Is called when the application terminates.
\r
225 * @param event - the QCloseEvent.
\r
227 void MainWindow::closeEvent(QCloseEvent *event)
\r
229 qDebug() << "Closed";
\r
234 * Is called when the Rotate menu item is triggered. Display orientation is saved in the QSettings.
\r
236 * @fn slotActionRotate
\r
237 * @param QAction* action - the action.
\r
239 void MainWindow::slotActionRotate(QAction* action)
\r
241 qDebug() << "Rotate" << action->text();
\r
242 landscape = !landscape;
\r
243 settings->setValue("Landscape", landscape);
\r
244 setLandscapeMode(landscape);
\r
248 * Set landscape/portrait mode.
\r
250 void MainWindow::setLandscapeMode(bool landscape)
\r
254 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
\r
255 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
259 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
\r
260 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
265 * Is called when the About menu item is triggered.
\r
267 * @fn slotActionAbout
\r
268 * @param QAction* action - the action.
\r
270 void MainWindow::slotActionAbout(QAction* action)
\r
272 qDebug() << "About" << action->text();
\r
274 aboutText.append("EasyList (c) 2010\n\n");
\r
275 aboutText.append("Created by Willem Liu.\n");
\r
276 aboutText.append("Created with QtCreator.\n");
\r
277 QMessageBox::about(this, "EasyList", aboutText);
\r