summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/notes/mainwindow.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/pim/notes/mainwindow.cpp b/core/pim/notes/mainwindow.cpp
index d10578a..68cb28b 100644
--- a/core/pim/notes/mainwindow.cpp
+++ b/core/pim/notes/mainwindow.cpp
@@ -1,255 +1,285 @@
1/* 1/*
2 * OPIE Notes 2 * OPIE Notes
3 * 3 *
4 * based on NoteZ 1.1.0 by Henning Holtschneider <hh@holtschneider.com> 4 * based on NoteZ 1.1.0 by Henning Holtschneider <hh@holtschneider.com>
5 * 5 *
6 * moved to OPIE Pim framework by Marcin Juszkiewicz <openembedded@hrw.one.pl> 6 * moved to OPIE Pim framework by Marcin Juszkiewicz <openembedded@hrw.one.pl>
7 * 7 *
8 * History: 8 * History:
9 * - 2005.10.12 - started work 9 * - 2005.10.12 - started work
10 * - 2005.10.19 - version 0.2: 10 * - 2005.10.19 - version 0.2:
11 * - first working version 11 * - first working version
12 * - info sent to NoteZ author and to OPIE devel 12 * - info sent to NoteZ author and to OPIE devel
13 * 13 *
14 * - 2005.10.20 - version 0.3: 14 * - 2005.10.20 - version 0.3:
15 * - load/save in UTF-8 15 * - load/save in UTF-8
16 * - load all files from Documents/text/plain 16 * - load all files from Documents/text/plain
17 * - create .txt files not .ntz - timestamp used as name 17 * - create .txt files not .ntz - timestamp used as name
18 * - one variable (documentsDirName) keep location of notes 18 * - one variable (documentsDirName) keep location of notes
19 * - code (re)indented and converted to spaces 19 * - code (re)indented and converted to spaces
20 * - variables translated to English (were in German) 20 * - variables translated to English (were in German)
21 * - started work on beaming 21 * - started work on beaming
22 * 22 *
23 * - 2005.10.26 - version 0.4:
24 * - added check does Documents/text/plain exist and create it if not
25 *
23 * ToDo: 26 * ToDo:
24 * - beaming 27 * - beaming
25 * - moving to SQLite database 28 * - moving to SQLite database
26 * - category support 29 * - category support
27 * - searching 30 * - searching
28 * 31 *
29 */ 32 */
30 33
31#include "mainwindow.h" 34#include "mainwindow.h"
32#include "editwindow.h" 35#include "editwindow.h"
33#include <qpe/ir.h> 36#include <qpe/ir.h>
34 37
35mainWindowWidget::mainWindowWidget( QWidget *parent, const char *name, WFlags) 38mainWindowWidget::mainWindowWidget( QWidget *parent, const char *name, WFlags)
36 : Opie::OPimMainWindow( "Notes", "Notes", tr( "Note" ), "notes", 39 : Opie::OPimMainWindow( "Notes", "Notes", tr( "Note" ), "notes",
37 parent, name, WType_TopLevel | WStyle_ContextHelp ) 40 parent, name, WType_TopLevel | WStyle_ContextHelp )
38{ 41{
39 setCaption( tr("Notes")); 42 setCaption( tr("Notes"));
40 notesList = new QListBox(this, "notesList"); 43 notesList = new QListBox(this, "notesList");
41 setCentralWidget(notesList); 44 setCentralWidget(notesList);
42 45
43 documentsDirName = QPEApplication::documentDir() + "/text/plain/"; 46 documentsDirName = QPEApplication::documentDir() + "/text/plain/";
47
48 fileList.setPath(documentsDirName);
49
50 if(!fileList.exists())
51 {
52 fileList.setPath(QPEApplication::documentDir() + "/text/");
53
54 if(!fileList.exists())
55 {
56 QString text;
57
58 if(!fileList.mkdir(fileList.absPath()))
59 {
60 QMessageBox::critical(0, tr("i/o error"), text.sprintf(tr("Could not create directory '%s'"), fileList.absPath()));
61 }
62 else
63 {
64 fileList.setPath(documentsDirName);
65
66 if(!fileList.mkdir(fileList.absPath()))
67 {
68 QMessageBox::critical(0, tr("i/o error"), text.sprintf(tr("Could not create directory '%s'"), fileList.absPath()));
69 }
70 }
71 }
72 }
73
44 this->selected = -1; 74 this->selected = -1;
45 refreshList(); 75 refreshList();
46 76
47 QObject::connect(notesList, SIGNAL(returnPressed(QListBoxItem*)), this, SLOT(slotItemEdit())); 77 QObject::connect(notesList, SIGNAL(returnPressed(QListBoxItem*)), this, SLOT(slotItemEdit()));
48 QObject::connect(notesList, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(slotItemEdit())); 78 QObject::connect(notesList, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(slotItemEdit()));
49} 79}
50 80
51void mainWindowWidget::deleteFile() 81void mainWindowWidget::deleteFile()
52{ 82{
53 if( notesList->count() > 0 ) 83 if( notesList->count() > 0 )
54 { 84 {
55 switch (QMessageBox::warning(0, tr("Delete note"), tr("Really delete\n'") + notesList->currentText() + "'?", 85 switch (QMessageBox::warning(0, tr("Delete note"), tr("Really delete\n'") + notesList->currentText() + "'?",
56 QMessageBox::Yes, QMessageBox::No)) 86 QMessageBox::Yes, QMessageBox::No))
57 { 87 {
58 case QMessageBox::Yes: 88 case QMessageBox::Yes:
59 this->selected = notesList->currentItem(); 89 this->selected = notesList->currentItem();
60 QFile::remove(documentsDirName + fileList[notesList->currentItem()]); 90 QFile::remove(documentsDirName + fileList[notesList->currentItem()]);
61 refreshList(); 91 refreshList();
62 break; 92 break;
63 93
64 case QMessageBox::No: 94 case QMessageBox::No:
65 // don't delete 95 // don't delete
66 break; 96 break;
67 } 97 }
68 } 98 }
69} 99}
70 100
71void mainWindowWidget::editFile(QString filename, int create) 101void mainWindowWidget::editFile(QString filename, int create)
72{ 102{
73 editWindowWidget *editWindow = new editWindowWidget(0, "editWindow", true); 103 editWindowWidget *editWindow = new editWindowWidget(0, "editWindow", true);
74 104
75 editWindow->loadFile(filename); 105 editWindow->loadFile(filename);
76 106
77 if(QPEApplication::execDialog(editWindow) == QDialog::Accepted) 107 if(QPEApplication::execDialog(editWindow) == QDialog::Accepted)
78 { 108 {
79 editWindow->saveFile(filename); 109 editWindow->saveFile(filename);
80 if( create ) 110 if( create )
81 { 111 {
82 // the new selection will be always at the end and count is already 112 // the new selection will be always at the end and count is already
83 // 1 bigger than selected 113 // 1 bigger than selected
84 this->selected = notesList->count(); 114 this->selected = notesList->count();
85 } 115 }
86 } 116 }
87 117
88 refreshList(); 118 refreshList();
89} 119}
90 120
91int mainWindowWidget::create() 121int mainWindowWidget::create()
92{ 122{
93 QString name; 123 QString name;
94 int now = time(0); 124 int now = time(0);
95 125
96 this->editFile(name.sprintf(documentsDirName + "%d.txt", now), true ); 126 this->editFile(name.sprintf(documentsDirName + "%d.txt", now), true );
97 127
98 return 0; //FIXME 128 return 0; //FIXME
99} 129}
100 130
101void mainWindowWidget::slotItemEdit() 131void mainWindowWidget::slotItemEdit()
102{ 132{
103 openFile(); 133 openFile();
104} 134}
105 135
106void mainWindowWidget::slotItemDelete() 136void mainWindowWidget::slotItemDelete()
107{ 137{
108 deleteFile(); 138 deleteFile();
109} 139}
110 140
111void mainWindowWidget::slotItemNew() 141void mainWindowWidget::slotItemNew()
112{ 142{
113 create(); 143 create();
114} 144}
115 145
116void mainWindowWidget::slotItemDuplicate() 146void mainWindowWidget::slotItemDuplicate()
117{ 147{
118 QString fileName = documentsDirName + fileList[notesList->currentItem()]; 148 QString fileName = documentsDirName + fileList[notesList->currentItem()];
119 int now = time(0); 149 int now = time(0);
120 150
121 QFile fileOld(fileName); 151 QFile fileOld(fileName);
122 152
123 if (fileOld.exists()) 153 if (fileOld.exists())
124 { 154 {
125 if (!fileOld.open(IO_ReadOnly)) 155 if (!fileOld.open(IO_ReadOnly))
126 { 156 {
127 QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not read file '%s'"), fileName)); 157 QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not read file '%s'"), fileName));
128 } 158 }
129 else 159 else
130 { 160 {
131 QFile fileNew(documentsDirName + fileName.sprintf("%d.txt", now)); 161 QFile fileNew(documentsDirName + fileName.sprintf("%d.txt", now));
132 162
133 if (!fileNew.exists()) 163 if (!fileNew.exists())
134 { 164 {
135 if(fileNew.open(IO_WriteOnly)) 165 if(fileNew.open(IO_WriteOnly))
136 { 166 {
137 QTextStream inStream(&fileOld); 167 QTextStream inStream(&fileOld);
138 inStream.setEncoding(QTextStream::UnicodeUTF8); 168 inStream.setEncoding(QTextStream::UnicodeUTF8);
139 169
140 QTextStream outStream(&fileNew); 170 QTextStream outStream(&fileNew);
141 outStream.setEncoding(QTextStream::UnicodeUTF8); 171 outStream.setEncoding(QTextStream::UnicodeUTF8);
142 outStream << inStream.read(); 172 outStream << inStream.read();
143 173
144 fileOld.close(); 174 fileOld.close();
145 fileNew.close(); 175 fileNew.close();
146 refreshList(); 176 refreshList();
147 } 177 }
148 } 178 }
149 } 179 }
150 } 180 }
151} 181}
152 182
153void mainWindowWidget::openFile() 183void mainWindowWidget::openFile()
154{ 184{
155 int number = notesList->currentItem(); 185 int number = notesList->currentItem();
156 186
157 if( notesList->count() > 0 ) 187 if( notesList->count() > 0 )
158 { 188 {
159 this->selected = number; 189 this->selected = number;
160 this->editFile(documentsDirName + fileList[number], false); 190 this->editFile(documentsDirName + fileList[number], false);
161 } 191 }
162} 192}
163 193
164void mainWindowWidget::refreshList() 194void mainWindowWidget::refreshList()
165{ 195{
166 unsigned int item; 196 unsigned int item;
167 QString title; 197 QString title;
168 198
169 notesList->clear(); 199 notesList->clear();
170 200
171 fileList.setPath(documentsDirName); 201 fileList.setPath(documentsDirName);
172 fileList.setFilter(QDir::Files); 202 fileList.setFilter(QDir::Files);
173 fileList.setSorting(QDir::Name); 203 fileList.setSorting(QDir::Name);
174 204
175 for (item = 0; item < fileList.count(); item++) 205 for (item = 0; item < fileList.count(); item++)
176 { 206 {
177 QFile file(documentsDirName + fileList[item]); 207 QFile file(documentsDirName + fileList[item]);
178 208
179 if (!file.open(IO_ReadOnly)) 209 if (!file.open(IO_ReadOnly))
180 { 210 {
181 QMessageBox::warning(0, tr("File i/o error"), title.sprintf(tr("Could not read file '%s'"), fileList[item])); 211 QMessageBox::warning(0, tr("File i/o error"), title.sprintf(tr("Could not read file '%s'"), fileList[item]));
182 } 212 }
183 else 213 else
184 { 214 {
185 QTextStream inStream(&file); 215 QTextStream inStream(&file);
186 inStream.setEncoding(QTextStream::UnicodeUTF8); 216 inStream.setEncoding(QTextStream::UnicodeUTF8);
187 217
188 if (!inStream.atEnd()) 218 if (!inStream.atEnd())
189 { 219 {
190 title = inStream.readLine(); 220 title = inStream.readLine();
191 } 221 }
192 else 222 else
193 { 223 {
194 title = tr("<empty file>"); 224 title = tr("<empty file>");
195 } 225 }
196 226
197 if (title.length() < 1) 227 if (title.length() < 1)
198 { 228 {
199 title = tr("<no caption>"); 229 title = tr("<no caption>");
200 } 230 }
201 231
202 file.close(); 232 file.close();
203 233
204 notesList->insertItem(title); 234 notesList->insertItem(title);
205 } 235 }
206 } 236 }
207 237
208 if( notesList->count() > 0 ) 238 if( notesList->count() > 0 )
209 { 239 {
210 if( this->selected == -1 ) 240 if( this->selected == -1 )
211 { 241 {
212 notesList->setCurrentItem( 0 ); 242 notesList->setCurrentItem( 0 );
213 } 243 }
214 else 244 else
215 { 245 {
216 if( notesList->count() > this->selected ) 246 if( notesList->count() > this->selected )
217 { 247 {
218 notesList->setCurrentItem( this->selected ); 248 notesList->setCurrentItem( this->selected );
219 } 249 }
220 else 250 else
221 { 251 {
222 notesList->setCurrentItem( notesList->count() - 1 ); 252 notesList->setCurrentItem( notesList->count() - 1 );
223 } 253 }
224 254
225 } 255 }
226 } 256 }
227 else 257 else
228 { 258 {
229 this->selected = -1; 259 this->selected = -1;
230 } 260 }
231 261
232} 262}
233 263
234void mainWindowWidget::slotItemBeam() 264void mainWindowWidget::slotItemBeam()
235{ 265{
236 Ir obex; 266 Ir obex;
237 267
238 obex.send(documentsDirName + fileList[notesList->currentItem()], "test", "text/plain"); 268 obex.send(documentsDirName + fileList[notesList->currentItem()], "test", "text/plain");
239} 269}
240 270
241void mainWindowWidget::slotItemFind() { toBeDone();} 271void mainWindowWidget::slotItemFind() { toBeDone();}
242void mainWindowWidget::slotConfigure() { toBeDone();} 272void mainWindowWidget::slotConfigure() { toBeDone();}
243void mainWindowWidget::flush() { toBeDone();} 273void mainWindowWidget::flush() { toBeDone();}
244void mainWindowWidget::reload() { toBeDone();} 274void mainWindowWidget::reload() { toBeDone();}
245bool mainWindowWidget::remove( int /*uid*/ ) { toBeDone(); return false; } 275bool mainWindowWidget::remove( int /*uid*/ ) { toBeDone(); return false; }
246void mainWindowWidget::beam( int /*uid*/ ) { toBeDone();} 276void mainWindowWidget::beam( int /*uid*/ ) { toBeDone();}
247void mainWindowWidget::show( int /*uid*/ ) { toBeDone();} 277void mainWindowWidget::show( int /*uid*/ ) { toBeDone();}
248void mainWindowWidget::edit( int /*uid*/ ) { toBeDone();} 278void mainWindowWidget::edit( int /*uid*/ ) { toBeDone();}
249void mainWindowWidget::add( const Opie::OPimRecord& ) { toBeDone();} 279void mainWindowWidget::add( const Opie::OPimRecord& ) { toBeDone();}
250 280
251void mainWindowWidget::toBeDone(void) 281void mainWindowWidget::toBeDone(void)
252{ 282{
253 QMessageBox::information( this, "Notes", tr("Not yet implemented")); 283 QMessageBox::information( this, "Notes", tr("Not yet implemented"));
254} 284}
255 285