|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtGui> |
|
43 |
|
44 #include <qservicemanager.h> |
|
45 #include <qserviceinterfacedescriptor.h> |
|
46 |
|
47 #include "sfwnotes.h" |
|
48 |
|
49 Q_DECLARE_METATYPE(QServiceInterfaceDescriptor) |
|
50 |
|
51 ToDoTool::ToDoTool(QWidget *parent, Qt::WindowFlags flags) |
|
52 : QWidget(parent, flags) |
|
53 { |
|
54 setupUi(this); |
|
55 |
|
56 serviceManager = new QServiceManager(this); |
|
57 |
|
58 registerExampleServices(); |
|
59 |
|
60 setWindowTitle(tr("ToDoTool")); |
|
61 |
|
62 init(); |
|
63 } |
|
64 |
|
65 ToDoTool::~ToDoTool() |
|
66 { |
|
67 unregisterExampleServices(); |
|
68 } |
|
69 |
|
70 void ToDoTool::soundAlarm(const QDateTime& alarm) |
|
71 { |
|
72 QString message = notesManager->property("alarmMessage").toString(); |
|
73 |
|
74 QMessageBox msgBox; |
|
75 msgBox.setWindowTitle("Alert"); |
|
76 msgBox.setText("ALARM SOUNDED!!!\n\n" +alarm.toString("yyyy-MM-dd HH:mm") + "\n\n" + message); |
|
77 msgBox.resize(200, msgBox.height()); |
|
78 msgBox.exec(); |
|
79 } |
|
80 |
|
81 void ToDoTool::init() |
|
82 { |
|
83 QServiceManager mgr; |
|
84 QServiceFilter filter; |
|
85 filter.setServiceName("NotesManagerService"); |
|
86 QList<QServiceInterfaceDescriptor> list = serviceManager->findInterfaces(filter); |
|
87 |
|
88 notesManager = mgr.loadInterface(list[0]); |
|
89 |
|
90 if (notesManager) |
|
91 notesManager->setParent(this); |
|
92 |
|
93 { |
|
94 currentNote = 1; |
|
95 searchWord = ""; |
|
96 refreshList(); |
|
97 |
|
98 QObject::connect(notesManager, SIGNAL(soundAlarm(QDateTime)), |
|
99 this, SLOT(soundAlarm(QDateTime))); |
|
100 } |
|
101 } |
|
102 |
|
103 void ToDoTool::registerExampleServices() |
|
104 { |
|
105 QStringList exampleXmlFiles; |
|
106 exampleXmlFiles << "notesmanagerservice.xml"; |
|
107 foreach (const QString &fileName, exampleXmlFiles) { |
|
108 QString path = QCoreApplication::applicationDirPath() + "/xmldata/" + fileName; |
|
109 serviceManager->addService(path); |
|
110 } |
|
111 } |
|
112 |
|
113 void ToDoTool::unregisterExampleServices() |
|
114 { |
|
115 serviceManager->removeService("NotesManagerService"); |
|
116 } |
|
117 |
|
118 void ToDoTool::refreshList() |
|
119 { |
|
120 QMetaObject::invokeMethod(notesManager, "getNotes", |
|
121 Q_RETURN_ARG(QList<QObject*>, ret), |
|
122 Q_ARG(QString, searchWord)); |
|
123 |
|
124 totalNotes = ret.size(); |
|
125 |
|
126 if (totalNotes < 1) { currentNote = 0; } |
|
127 else if (totalNotes > 0 && currentNote == 0) { currentNote = 1; } |
|
128 |
|
129 refreshNotes(); |
|
130 } |
|
131 |
|
132 void ToDoTool::refreshNotes() |
|
133 { |
|
134 countLabel->setText(QString::number(currentNote) + "/" + QString::number(totalNotes)); |
|
135 |
|
136 if (currentNote == 0) { |
|
137 dateLabel->setText(""); |
|
138 noteLabel->setText("Click + to add a note"); |
|
139 } |
|
140 else { |
|
141 QDateTime alarm; |
|
142 QMetaObject::invokeMethod(ret[currentNote-1], "alarm", Q_RETURN_ARG(QDateTime, alarm)); |
|
143 dateLabel->setText(alarm.toString("yyyy-MM-dd HH:mm")); |
|
144 |
|
145 QString note; |
|
146 QMetaObject::invokeMethod(ret[currentNote-1], "message", Q_RETURN_ARG(QString, note)); |
|
147 noteLabel->setText(note); |
|
148 } |
|
149 } |
|
150 |
|
151 void ToDoTool::on_nextButton_clicked() |
|
152 { |
|
153 if (currentNote < totalNotes) { |
|
154 currentNote++; |
|
155 refreshNotes(); |
|
156 } |
|
157 } |
|
158 |
|
159 void ToDoTool::on_prevButton_clicked() |
|
160 { |
|
161 if (currentNote > 1) { |
|
162 currentNote--; |
|
163 refreshNotes(); |
|
164 } |
|
165 } |
|
166 |
|
167 void ToDoTool::on_addButton_clicked() |
|
168 { |
|
169 // re-implement date-time input method |
|
170 |
|
171 bool ok; |
|
172 QString newNote = QInputDialog::getText(this, tr("ToDoTool"), |
|
173 tr("Add a new note + alarm of format:\nnote#yyyy-mm-dd#hh:mm"), |
|
174 QLineEdit::Normal, "", &ok); |
|
175 |
|
176 if (ok && !newNote.isEmpty()) { |
|
177 QStringList note = newNote.split(QRegExp("#")); |
|
178 |
|
179 if (note.size() == 3) { |
|
180 |
|
181 QStringList date = note.at(1).split("-"); |
|
182 QStringList time = note.at(2).split(":"); |
|
183 |
|
184 if (date.size() == 3 && time.size() == 2) { |
|
185 QDateTime alarm = QDateTime::fromString(note.at(1)+" "+note.at(2),"yyyy-MM-dd HH:mm"); |
|
186 QMetaObject::invokeMethod(notesManager, "addNote", |
|
187 Q_ARG(QString, note.at(0)), |
|
188 Q_ARG(QDateTime, alarm)); |
|
189 } |
|
190 } else { |
|
191 QMetaObject::invokeMethod(notesManager, "addNote", |
|
192 Q_ARG(QString, note.at(0)), |
|
193 Q_ARG(QDateTime, QDateTime::currentDateTime())); |
|
194 } |
|
195 |
|
196 refreshList(); |
|
197 } |
|
198 } |
|
199 |
|
200 void ToDoTool::on_deleteButton_clicked() |
|
201 { |
|
202 if (currentNote != 0) { |
|
203 QMessageBox msgBox; |
|
204 msgBox.setText("Confirm removing this note?"); |
|
205 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); |
|
206 |
|
207 if (msgBox.exec() == QMessageBox::Ok) { |
|
208 int index; |
|
209 QMetaObject::invokeMethod(ret[currentNote-1], "index", Q_RETURN_ARG(int, index)); |
|
210 |
|
211 QMetaObject::invokeMethod(notesManager, "removeNote", Q_ARG(int, index)); |
|
212 if (currentNote > 1) |
|
213 currentNote--; |
|
214 |
|
215 refreshList(); |
|
216 } |
|
217 } |
|
218 } |
|
219 |
|
220 void ToDoTool::on_searchButton_clicked() |
|
221 { |
|
222 bool ok; |
|
223 QString searchNote = QInputDialog::getText(this, tr("ToDoTool"), tr("Find a note:"), |
|
224 QLineEdit::Normal, "", &ok); |
|
225 if (ok) { |
|
226 if (searchNote.isEmpty()) |
|
227 searchWord = ""; |
|
228 else |
|
229 searchWord = searchNote; |
|
230 |
|
231 currentNote = 1; |
|
232 refreshList(); |
|
233 } |
|
234 } |
|
235 |