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
@@ -50,12 +50,13 @@ MainWindow::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);
@@ -68,20 +69,21 @@ MainWindow::MainWindow()
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());
@@ -97,14 +99,14 @@ void MainWindow::documentSave(DocLnk &lnkDoc)
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}
@@ -169,40 +171,33 @@ int MainWindow::saveCurrentFile(bool ask=TRUE)
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);
@@ -220,13 +215,14 @@ void MainWindow::closeEvent(QCloseEvent *e)
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}
@@ -751,15 +747,17 @@ void MainWindow::slotColumnHide()
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);
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
@@ -36,13 +36,13 @@ typedef struct typeSheet
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,
@@ -73,14 +73,13 @@ class MainWindow: public QMainWindow
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: