summaryrefslogtreecommitdiff
path: root/core/pim
authorhrw <hrw>2005-10-20 14:55:34 (UTC)
committer hrw <hrw>2005-10-20 14:55:34 (UTC)
commit57abd83eb7b79b95301de36dc178174d9b28b6c2 (patch) (unidiff)
treeb869bb94ec37a278bfed66877a1320d807399f94 /core/pim
parent0f25331618ea6cac8a59f2c2298a9e1684748b97 (diff)
downloadopie-57abd83eb7b79b95301de36dc178174d9b28b6c2.zip
opie-57abd83eb7b79b95301de36dc178174d9b28b6c2.tar.gz
opie-57abd83eb7b79b95301de36dc178174d9b28b6c2.tar.bz2
added Opie-Notes
Diffstat (limited to 'core/pim') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/notes/editwindow.cpp57
-rw-r--r--core/pim/notes/editwindow.h22
-rw-r--r--core/pim/notes/main.cpp12
-rw-r--r--core/pim/notes/mainwindow.cpp255
-rw-r--r--core/pim/notes/mainwindow.h52
-rw-r--r--core/pim/notes/opie-notes.pro11
6 files changed, 409 insertions, 0 deletions
diff --git a/core/pim/notes/editwindow.cpp b/core/pim/notes/editwindow.cpp
new file mode 100644
index 0000000..1b2d4a6
--- a/dev/null
+++ b/core/pim/notes/editwindow.cpp
@@ -0,0 +1,57 @@
1#include "editwindow.h"
2
3editWindowWidget::editWindowWidget( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl )
4{
5 setCaption( tr( "Information:" ) );
6 QGridLayout *gridLayout = new QGridLayout(this, 1, 1, 5, 5);
7 editArea = new QMultiLineEdit(this, "editArea");
8 gridLayout->addWidget(editArea, 0, 0);
9 editArea->setWordWrap(QMultiLineEdit::WidgetWidth);
10
11 showMaximized();
12}
13
14void editWindowWidget::loadFile(QString fileName)
15{
16 QFileInfo fileinfo(fileName);
17 setCaption(fileinfo.fileName());
18
19 QFile file(fileName);
20
21 if (file.exists())
22 {
23 if (!file.open(IO_ReadOnly))
24 {
25 QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not read file '%s'"), fileName));
26 }
27 else
28 {
29 QTextStream inStream(&file);
30 inStream.setEncoding(QTextStream::UnicodeUTF8);
31 editArea->setText(inStream.read());
32 file.close();
33 }
34 }
35}
36
37void editWindowWidget::saveFile(QString fileName)
38{
39 QFile file(fileName);
40
41 if(!file.open(IO_WriteOnly))
42 {
43 QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not write file '%s'"), fileName));
44 }
45 else
46 {
47 QTextStream outStream(&file);
48 outStream.setEncoding(QTextStream::UnicodeUTF8);
49 outStream << editArea->text();
50 file.close();
51 this->accept();
52 }
53}
54
55editWindowWidget::~editWindowWidget()
56{
57}
diff --git a/core/pim/notes/editwindow.h b/core/pim/notes/editwindow.h
new file mode 100644
index 0000000..57c5241
--- a/dev/null
+++ b/core/pim/notes/editwindow.h
@@ -0,0 +1,22 @@
1#include <qdialog.h>
2#include <qlayout.h>
3#include <qmultilineedit.h>
4#include <qmessagebox.h>
5#include <qtextstream.h>
6#include <qfile.h>
7#include <qfileinfo.h>
8
9class editWindowWidget : public QDialog
10{
11 Q_OBJECT
12
13 public:
14 editWindowWidget::editWindowWidget(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0);
15 ~editWindowWidget();
16 void loadFile(QString fileName);
17 void saveFile(QString fileName);
18
19 private:
20 QMultiLineEdit *editArea;
21
22};
diff --git a/core/pim/notes/main.cpp b/core/pim/notes/main.cpp
new file mode 100644
index 0000000..c69fa93
--- a/dev/null
+++ b/core/pim/notes/main.cpp
@@ -0,0 +1,12 @@
1#include "mainwindow.h"
2
3int main(int argc, char* argv[])
4{
5 QPEApplication a(argc, argv);
6
7 mainWindowWidget mainWindow;
8
9 a.showMainWidget(&mainWindow);
10
11 return a.exec();
12}
diff --git a/core/pim/notes/mainwindow.cpp b/core/pim/notes/mainwindow.cpp
new file mode 100644
index 0000000..d10578a
--- a/dev/null
+++ b/core/pim/notes/mainwindow.cpp
@@ -0,0 +1,255 @@
1/*
2 * OPIE Notes
3 *
4 * based on NoteZ 1.1.0 by Henning Holtschneider <hh@holtschneider.com>
5 *
6 * moved to OPIE Pim framework by Marcin Juszkiewicz <openembedded@hrw.one.pl>
7 *
8 * History:
9 * - 2005.10.12 - started work
10 * - 2005.10.19 - version 0.2:
11 * - first working version
12 * - info sent to NoteZ author and to OPIE devel
13 *
14 * - 2005.10.20 - version 0.3:
15 * - load/save in UTF-8
16 * - load all files from Documents/text/plain
17 * - create .txt files not .ntz - timestamp used as name
18 * - one variable (documentsDirName) keep location of notes
19 * - code (re)indented and converted to spaces
20 * - variables translated to English (were in German)
21 * - started work on beaming
22 *
23 * ToDo:
24 * - beaming
25 * - moving to SQLite database
26 * - category support
27 * - searching
28 *
29 */
30
31#include "mainwindow.h"
32#include "editwindow.h"
33#include <qpe/ir.h>
34
35mainWindowWidget::mainWindowWidget( QWidget *parent, const char *name, WFlags)
36 : Opie::OPimMainWindow( "Notes", "Notes", tr( "Note" ), "notes",
37 parent, name, WType_TopLevel | WStyle_ContextHelp )
38{
39 setCaption( tr("Notes"));
40 notesList = new QListBox(this, "notesList");
41 setCentralWidget(notesList);
42
43 documentsDirName = QPEApplication::documentDir() + "/text/plain/";
44 this->selected = -1;
45 refreshList();
46
47 QObject::connect(notesList, SIGNAL(returnPressed(QListBoxItem*)), this, SLOT(slotItemEdit()));
48 QObject::connect(notesList, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(slotItemEdit()));
49}
50
51void mainWindowWidget::deleteFile()
52{
53 if( notesList->count() > 0 )
54 {
55 switch (QMessageBox::warning(0, tr("Delete note"), tr("Really delete\n'") + notesList->currentText() + "'?",
56 QMessageBox::Yes, QMessageBox::No))
57 {
58 case QMessageBox::Yes:
59 this->selected = notesList->currentItem();
60 QFile::remove(documentsDirName + fileList[notesList->currentItem()]);
61 refreshList();
62 break;
63
64 case QMessageBox::No:
65 // don't delete
66 break;
67 }
68 }
69}
70
71void mainWindowWidget::editFile(QString filename, int create)
72{
73 editWindowWidget *editWindow = new editWindowWidget(0, "editWindow", true);
74
75 editWindow->loadFile(filename);
76
77 if(QPEApplication::execDialog(editWindow) == QDialog::Accepted)
78 {
79 editWindow->saveFile(filename);
80 if( create )
81 {
82 // the new selection will be always at the end and count is already
83 // 1 bigger than selected
84 this->selected = notesList->count();
85 }
86 }
87
88 refreshList();
89}
90
91int mainWindowWidget::create()
92{
93 QString name;
94 int now = time(0);
95
96 this->editFile(name.sprintf(documentsDirName + "%d.txt", now), true );
97
98 return 0; //FIXME
99}
100
101void mainWindowWidget::slotItemEdit()
102{
103 openFile();
104}
105
106void mainWindowWidget::slotItemDelete()
107{
108 deleteFile();
109}
110
111void mainWindowWidget::slotItemNew()
112{
113 create();
114}
115
116void mainWindowWidget::slotItemDuplicate()
117{
118 QString fileName = documentsDirName + fileList[notesList->currentItem()];
119 int now = time(0);
120
121 QFile fileOld(fileName);
122
123 if (fileOld.exists())
124 {
125 if (!fileOld.open(IO_ReadOnly))
126 {
127 QMessageBox::warning(0, tr("File i/o error"), fileName.sprintf(tr("Could not read file '%s'"), fileName));
128 }
129 else
130 {
131 QFile fileNew(documentsDirName + fileName.sprintf("%d.txt", now));
132
133 if (!fileNew.exists())
134 {
135 if(fileNew.open(IO_WriteOnly))
136 {
137 QTextStream inStream(&fileOld);
138 inStream.setEncoding(QTextStream::UnicodeUTF8);
139
140 QTextStream outStream(&fileNew);
141 outStream.setEncoding(QTextStream::UnicodeUTF8);
142 outStream << inStream.read();
143
144 fileOld.close();
145 fileNew.close();
146 refreshList();
147 }
148 }
149 }
150 }
151}
152
153void mainWindowWidget::openFile()
154{
155 int number = notesList->currentItem();
156
157 if( notesList->count() > 0 )
158 {
159 this->selected = number;
160 this->editFile(documentsDirName + fileList[number], false);
161 }
162}
163
164void mainWindowWidget::refreshList()
165{
166 unsigned int item;
167 QString title;
168
169 notesList->clear();
170
171 fileList.setPath(documentsDirName);
172 fileList.setFilter(QDir::Files);
173 fileList.setSorting(QDir::Name);
174
175 for (item = 0; item < fileList.count(); item++)
176 {
177 QFile file(documentsDirName + fileList[item]);
178
179 if (!file.open(IO_ReadOnly))
180 {
181 QMessageBox::warning(0, tr("File i/o error"), title.sprintf(tr("Could not read file '%s'"), fileList[item]));
182 }
183 else
184 {
185 QTextStream inStream(&file);
186 inStream.setEncoding(QTextStream::UnicodeUTF8);
187
188 if (!inStream.atEnd())
189 {
190 title = inStream.readLine();
191 }
192 else
193 {
194 title = tr("<empty file>");
195 }
196
197 if (title.length() < 1)
198 {
199 title = tr("<no caption>");
200 }
201
202 file.close();
203
204 notesList->insertItem(title);
205 }
206 }
207
208 if( notesList->count() > 0 )
209 {
210 if( this->selected == -1 )
211 {
212 notesList->setCurrentItem( 0 );
213 }
214 else
215 {
216 if( notesList->count() > this->selected )
217 {
218 notesList->setCurrentItem( this->selected );
219 }
220 else
221 {
222 notesList->setCurrentItem( notesList->count() - 1 );
223 }
224
225 }
226 }
227 else
228 {
229 this->selected = -1;
230 }
231
232}
233
234void mainWindowWidget::slotItemBeam()
235{
236 Ir obex;
237
238 obex.send(documentsDirName + fileList[notesList->currentItem()], "test", "text/plain");
239}
240
241void mainWindowWidget::slotItemFind() { toBeDone();}
242void mainWindowWidget::slotConfigure() { toBeDone();}
243void mainWindowWidget::flush() { toBeDone();}
244void mainWindowWidget::reload() { toBeDone();}
245bool mainWindowWidget::remove( int /*uid*/ ) { toBeDone(); return false; }
246void mainWindowWidget::beam( int /*uid*/ ) { toBeDone();}
247void mainWindowWidget::show( int /*uid*/ ) { toBeDone();}
248void mainWindowWidget::edit( int /*uid*/ ) { toBeDone();}
249void mainWindowWidget::add( const Opie::OPimRecord& ) { toBeDone();}
250
251void mainWindowWidget::toBeDone(void)
252{
253 QMessageBox::information( this, "Notes", tr("Not yet implemented"));
254}
255
diff --git a/core/pim/notes/mainwindow.h b/core/pim/notes/mainwindow.h
new file mode 100644
index 0000000..32431ef
--- a/dev/null
+++ b/core/pim/notes/mainwindow.h
@@ -0,0 +1,52 @@
1#include <qpe/qpeapplication.h>
2#include <qlistbox.h>
3#include <qdir.h>
4#include <qfile.h>
5#include <qtextstream.h>
6#include <qmessagebox.h>
7
8#include <opie2/opimmainwindow.h>
9#include <opie2/owidgetstack.h>
10
11class mainWindowWidget : public Opie::OPimMainWindow
12{
13 Q_OBJECT
14
15 public:
16 QListBox *notesList;
17 QDir fileList;
18
19 mainWindowWidget( QWidget *parent=0, const char *name=0, WFlags fl=0 );
20 void refreshList();
21
22 public slots:
23 void openFile();
24 void deleteFile();
25
26 private:
27 int selected;
28 QString fileName;
29 QString documentsDirName;
30
31 void editFile(QString filename, int create);
32 void toBeDone(void);
33
34 private slots:
35 void slotItemNew();
36 void slotItemEdit();
37 void slotItemDuplicate();
38 void slotItemDelete();
39 void slotItemBeam();
40 void slotItemFind();
41 void slotConfigure();
42
43 protected slots:
44 void flush();
45 void reload();
46 int create();
47 bool remove( int uid );
48 void beam( int uid);
49 void show( int uid );
50 void edit( int uid );
51 void add( const Opie::OPimRecord& );
52};
diff --git a/core/pim/notes/opie-notes.pro b/core/pim/notes/opie-notes.pro
new file mode 100644
index 0000000..6a343d8
--- a/dev/null
+++ b/core/pim/notes/opie-notes.pro
@@ -0,0 +1,11 @@
1TEMPLATE = app
2CONFIG = qt warn_on
3
4INCLUDEPATH += $(OPIEDIR)/include
5DEPENDPATH += $(OPIEDIR)/include
6LIBS += -lqpe -lopiecore2 -lopieui2 -lopiepim2
7
8HEADERS = mainwindow.h editwindow.h
9SOURCES = mainwindow.cpp main.cpp editwindow.cpp
10
11include( $(OPIEDIR)/include.pro )