summaryrefslogtreecommitdiff
authorleseb <leseb>2002-07-06 20:45:39 (UTC)
committer leseb <leseb>2002-07-06 20:45:39 (UTC)
commit7c069ad1b76c681282499b157ef9b23ec000947d (patch) (unidiff)
tree677ae3903f6448a4f761e3a1245c7e4a746b8a1a
parent2517236d77e1f2a3d255c4c540a39f1661caaff9 (diff)
downloadopie-7c069ad1b76c681282499b157ef9b23ec000947d.zip
opie-7c069ad1b76c681282499b157ef9b23ec000947d.tar.gz
opie-7c069ad1b76c681282499b157ef9b23ec000947d.tar.bz2
Fix DocLnk management to save documents correctly
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/mainwindow.cpp38
-rw-r--r--noncore/apps/opie-sheet/mainwindow.h5
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
@@ -48,16 +48,17 @@
48 48
49MainWindow::MainWindow() 49MainWindow::MainWindow()
50 :QMainWindow() 50 :QMainWindow()
51{ 51{
52 // initialize variables 52 // initialize variables
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 &)));
59 connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); 60 connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &)));
60 61
61 listSheets.setAutoDelete(TRUE); 62 listSheets.setAutoDelete(TRUE);
62 63
63 initActions(); 64 initActions();
@@ -66,24 +67,25 @@ MainWindow::MainWindow()
66 initFunctionsToolbar(); 67 initFunctionsToolbar();
67 initStandardToolbar(); 68 initStandardToolbar();
68 initSheet(); 69 initSheet();
69 70
70 // set window title 71 // set window title
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
77MainWindow::~MainWindow() 78MainWindow::~MainWindow()
78{ 79{
80 if (currentDoc) delete currentDoc;
79} 81}
80 82
81void MainWindow::documentSave(DocLnk &lnkDoc) 83void MainWindow::documentSave(DocLnk *lnkDoc)
82{ 84{
83 FileManager fm; 85 FileManager fm;
84 QByteArray streamBuffer; 86 QByteArray streamBuffer;
85 QDataStream stream(streamBuffer, IO_WriteOnly); 87 QDataStream stream(streamBuffer, IO_WriteOnly);
86 88
87 typeSheet *currentSheet=findSheet(sheet->getName()); 89 typeSheet *currentSheet=findSheet(sheet->getName());
88 if (!currentSheet) 90 if (!currentSheet)
89 { 91 {
@@ -95,18 +97,18 @@ void MainWindow::documentSave(DocLnk &lnkDoc)
95 stream << (Q_UINT32)listSheets.count(); 97 stream << (Q_UINT32)listSheets.count();
96 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) 98 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
97 { 99 {
98 stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); 100 stream << tempSheet->name << (Q_UINT32)tempSheet->data.count();
99 for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) 101 for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next())
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;
108 } 110 }
109 documentModified=FALSE; 111 documentModified=FALSE;
110} 112}
111 113
112void MainWindow::documentOpen(const DocLnk &lnkDoc) 114void MainWindow::documentOpen(const DocLnk &lnkDoc)
@@ -167,44 +169,37 @@ void MainWindow::documentOpen(const DocLnk &lnkDoc)
167int MainWindow::saveCurrentFile(bool ask=TRUE) 169int MainWindow::saveCurrentFile(bool ask=TRUE)
168{ 170{
169 if (ask) 171 if (ask)
170 { 172 {
171 int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); 173 int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
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
187void 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
197void MainWindow::selectorFileNew(const DocLnk &lnkDoc) 191void 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
206 typeSheet *newSheet=createNewSheet(); 201 typeSheet *newSheet=createNewSheet();
207 newSheet->data.setAutoDelete(TRUE); 202 newSheet->data.setAutoDelete(TRUE);
208 sheet->setName(newSheet->name); 203 sheet->setName(newSheet->name);
209 sheet->setSheetData(&newSheet->data); 204 sheet->setSheetData(&newSheet->data);
210 for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) 205 for (int i=1; i<DEFAULT_NUM_SHEETS; ++i)
@@ -218,17 +213,18 @@ void MainWindow::closeEvent(QCloseEvent *e)
218 else e->accept(); 213 else e->accept();
219} 214}
220 215
221void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) 216void MainWindow::selectorFileOpen(const DocLnk &lnkDoc)
222{ 217{
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
230 documentOpen(lnkDoc); 226 documentOpen(lnkDoc);
231 documentModified=FALSE; 227 documentModified=FALSE;
232} 228}
233 229
234void MainWindow::selectorShow() 230void MainWindow::selectorShow()
@@ -749,19 +745,21 @@ void MainWindow::slotColumnHide()
749 745
750 for (int col=col1; col<=col2; ++col) 746 for (int col=col1; col<=col2; ++col)
751 sheet->hideColumn(col); 747 sheet->hideColumn(col);
752} 748}
753 749
754void MainWindow::slotFileSaveAs() 750void 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
763void MainWindow::slotSheetRename() 761void MainWindow::slotSheetRename()
764{ 762{
765 TextDialog dialogText(this); 763 TextDialog dialogText(this);
766 if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; 764 if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
767 QString newName=dialogText.getValue(); 765 QString newName=dialogText.getValue();
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
@@ -34,17 +34,17 @@ typedef struct typeSheet
34 QList<typeCellData> data; 34 QList<typeCellData> data;
35}; 35};
36 36
37class MainWindow: public QMainWindow 37class MainWindow: public QMainWindow
38{ 38{
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;
46 46
47 // QT objects 47 // QT objects
48 QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp, 48 QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp,
49 *submenuFunc, *submenuFuncStd, *submenuFuncMath, *submenuFuncStat, 49 *submenuFunc, *submenuFuncStd, *submenuFuncMath, *submenuFuncStat,
50 *submenuRow, *submenuCol, *submenuSheet; 50 *submenuRow, *submenuCol, *submenuSheet;
@@ -71,18 +71,17 @@ class MainWindow: public QMainWindow
71 void initActions(); 71 void initActions();
72 void initFunctionsToolbar(); 72 void initFunctionsToolbar();
73 void initEditToolbar(); 73 void initEditToolbar();
74 void initStandardToolbar(); 74 void initStandardToolbar();
75 void initSheet(); 75 void initSheet();
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();
84 typeSheet *findSheet(const QString &name); 83 typeSheet *findSheet(const QString &name);
85 84
86 private slots: 85 private slots:
87 void slotFileNew(); 86 void slotFileNew();
88 void slotFileOpen(); 87 void slotFileOpen();