author | leseb <leseb> | 2002-07-06 20:45:39 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-07-06 20:45:39 (UTC) |
commit | 7c069ad1b76c681282499b157ef9b23ec000947d (patch) (unidiff) | |
tree | 677ae3903f6448a4f761e3a1245c7e4a746b8a1a /noncore | |
parent | 2517236d77e1f2a3d255c4c540a39f1661caaff9 (diff) | |
download | opie-7c069ad1b76c681282499b157ef9b23ec000947d.zip opie-7c069ad1b76c681282499b157ef9b23ec000947d.tar.gz opie-7c069ad1b76c681282499b157ef9b23ec000947d.tar.bz2 |
Fix DocLnk management to save documents correctly
-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.cpp | 38 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.h | 5 |
2 files changed, 20 insertions, 23 deletions
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp index efbcc20..09ee68b 100644 --- a/noncore/apps/opie-sheet/mainwindow.cpp +++ b/noncore/apps/opie-sheet/mainwindow.cpp | |||
@@ -53,6 +53,7 @@ MainWindow::MainWindow() | |||
53 | documentModified=FALSE; | 53 | documentModified=FALSE; |
54 | 54 | ||
55 | // construct objects | 55 | // construct objects |
56 | currentDoc=0; | ||
56 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); | 57 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); |
57 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); | 58 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); |
58 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); | 59 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); |
@@ -71,14 +72,15 @@ MainWindow::MainWindow() | |||
71 | setCaption(tr("Opie Sheet")); | 72 | setCaption(tr("Opie Sheet")); |
72 | 73 | ||
73 | // create sheets | 74 | // create sheets |
74 | selectorFileNew(currentDoc); | 75 | selectorFileNew(DocLnk()); |
75 | } | 76 | } |
76 | 77 | ||
77 | MainWindow::~MainWindow() | 78 | MainWindow::~MainWindow() |
78 | { | 79 | { |
80 | if (currentDoc) delete currentDoc; | ||
79 | } | 81 | } |
80 | 82 | ||
81 | void MainWindow::documentSave(DocLnk &lnkDoc) | 83 | void MainWindow::documentSave(DocLnk *lnkDoc) |
82 | { | 84 | { |
83 | FileManager fm; | 85 | FileManager fm; |
84 | QByteArray streamBuffer; | 86 | QByteArray streamBuffer; |
@@ -100,8 +102,8 @@ void MainWindow::documentSave(DocLnk &lnkDoc) | |||
100 | stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data; | 102 | stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data; |
101 | } | 103 | } |
102 | 104 | ||
103 | lnkDoc.setType("application/sheet-qt"); | 105 | lnkDoc->setType("application/sheet-qt"); |
104 | if (!fm.saveFile(lnkDoc, streamBuffer)) | 106 | if (!fm.saveFile(*lnkDoc, streamBuffer)) |
105 | { | 107 | { |
106 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); | 108 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); |
107 | return; | 109 | return; |
@@ -172,34 +174,27 @@ int MainWindow::saveCurrentFile(bool ask=TRUE) | |||
172 | if (result!=QMessageBox::Yes) return result; | 174 | if (result!=QMessageBox::Yes) return result; |
173 | } | 175 | } |
174 | 176 | ||
175 | if (currentDoc.name().isEmpty() || !currentDoc.isValid()) | 177 | if (!currentDoc->isValid()) |
176 | { | 178 | { |
177 | TextDialog dialogText(this); | 179 | TextDialog dialogText(this); |
178 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; | 180 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; |
179 | 181 | ||
180 | currentDoc.setName(dialogText.getValue()); | 182 | currentDoc->setName(dialogText.getValue()); |
183 | currentDoc->setFile(QString::null); | ||
184 | currentDoc->setLinkFile(QString::null); | ||
181 | } | 185 | } |
182 | 186 | ||
183 | documentSave(currentDoc); | 187 | documentSave(currentDoc); |
184 | return QMessageBox::Yes; | 188 | return QMessageBox::Yes; |
185 | } | 189 | } |
186 | 190 | ||
187 | void MainWindow::copyDocLnk(const DocLnk &source, DocLnk &target) | ||
188 | { | ||
189 | target.setName(source.name()); | ||
190 | target.setFile(source.file()); | ||
191 | target.setLinkFile(source.linkFile()); | ||
192 | target.setComment(source.comment()); | ||
193 | target.setType(source.type()); | ||
194 | target.setCategories(source.categories()); | ||
195 | } | ||
196 | |||
197 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) | 191 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) |
198 | { | 192 | { |
199 | selectorHide(); | 193 | selectorHide(); |
200 | 194 | ||
201 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 195 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
202 | copyDocLnk(lnkDoc, currentDoc); | 196 | if (currentDoc) delete currentDoc; |
197 | currentDoc = new DocLnk(lnkDoc); | ||
203 | listSheets.clear(); | 198 | listSheets.clear(); |
204 | comboSheets->clear(); | 199 | comboSheets->clear(); |
205 | 200 | ||
@@ -223,7 +218,8 @@ void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) | |||
223 | selectorHide(); | 218 | selectorHide(); |
224 | 219 | ||
225 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 220 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
226 | copyDocLnk(lnkDoc, currentDoc); | 221 | if (currentDoc) delete currentDoc; |
222 | currentDoc = new DocLnk(lnkDoc); | ||
227 | listSheets.clear(); | 223 | listSheets.clear(); |
228 | comboSheets->clear(); | 224 | comboSheets->clear(); |
229 | 225 | ||
@@ -754,9 +750,11 @@ void MainWindow::slotColumnHide() | |||
754 | void MainWindow::slotFileSaveAs() | 750 | void MainWindow::slotFileSaveAs() |
755 | { | 751 | { |
756 | TextDialog dialogText(this); | 752 | TextDialog dialogText(this); |
757 | if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc.name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; | 753 | if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; |
758 | 754 | ||
759 | currentDoc.setName(dialogText.getValue()); | 755 | currentDoc->setName(dialogText.getValue()); |
756 | currentDoc->setFile(QString::null); | ||
757 | currentDoc->setLinkFile(QString::null); | ||
760 | documentSave(currentDoc); | 758 | documentSave(currentDoc); |
761 | } | 759 | } |
762 | 760 | ||
diff --git a/noncore/apps/opie-sheet/mainwindow.h b/noncore/apps/opie-sheet/mainwindow.h index 554e6f6..d68e25c 100644 --- a/noncore/apps/opie-sheet/mainwindow.h +++ b/noncore/apps/opie-sheet/mainwindow.h | |||
@@ -39,7 +39,7 @@ class MainWindow: public QMainWindow | |||
39 | Q_OBJECT | 39 | Q_OBJECT |
40 | 40 | ||
41 | // QPE objects | 41 | // QPE objects |
42 | DocLnk currentDoc; | 42 | DocLnk* currentDoc; |
43 | QPEMenuBar *menu; | 43 | QPEMenuBar *menu; |
44 | QPEToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard; | 44 | QPEToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard; |
45 | FileSelector *fileSelector; | 45 | FileSelector *fileSelector; |
@@ -76,8 +76,7 @@ class MainWindow: public QMainWindow | |||
76 | void addToData(const QString &data); | 76 | void addToData(const QString &data); |
77 | int saveCurrentFile(bool ask=TRUE); | 77 | int saveCurrentFile(bool ask=TRUE); |
78 | void documentOpen(const DocLnk &lnkDoc); | 78 | void documentOpen(const DocLnk &lnkDoc); |
79 | void copyDocLnk(const DocLnk &source, DocLnk &target); | 79 | void documentSave(DocLnk *lnkDoc); |
80 | void documentSave(DocLnk &lnkDoc); | ||
81 | void closeEvent(QCloseEvent *e); | 80 | void closeEvent(QCloseEvent *e); |
82 | void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w); | 81 | void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w); |
83 | typeSheet *createNewSheet(); | 82 | typeSheet *createNewSheet(); |