From 47556496969ef4c98f36d54c0dd1eac44d2d6caf Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 1 Dec 2000 21:20:04 +0000 Subject: [PATCH] Have fixed the saving.. Hopefully this will work.. --- file.cpp | 44 -------------------------------------------- mainwindow.cpp | 41 +++++++++++++++++++++++++++++++++-------- mainwindow.h | 4 +++- 3 files changed, 36 insertions(+), 53 deletions(-) delete mode 100644 file.cpp diff --git a/file.cpp b/file.cpp deleted file mode 100644 index 86e57d1..0000000 --- a/file.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include "functions.h" -#include - -void load() -{ - ifstream in("/root/.adress"); - - while (!in.eof()) - { - string fname; - string lname; - string adr; - string pn; - getline(in, fname); -// cout << "Skapar " << fname << "\n"; -// cin.get(); - getline(in, lname); - getline(in, adr); - getline(in, pn); - if (fname == "" && lname == "" && lname == "" && pn == "") - continue; - (void) new CContact(fname, lname, adr, pn); - } -} - -void save() -{ - ofstream out; - out.open("/root/.adress"); - - CContact* contact = CContact::getFirst(); - - while ( contact != '\0') - { - out << contact->firstname() << "\n"; - out << contact->lastname() << "\n"; - out << contact->adress() << "\n"; - out << contact->phoneNumber() << "\n"; - contact=contact->getNext(); - } - out.close(); -} diff --git a/mainwindow.cpp b/mainwindow.cpp index 97c8a71..68afb43 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -14,7 +14,7 @@ MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) : CMainWindowBase( parent, name, fl ) { - //connect(LoadButton, SIGNAL(clicked()), SLOT(slotLoad())); + slotLoad(); } /* @@ -30,7 +30,27 @@ MainWindow::~MainWindow() */ void MainWindow::slotSave() { - qWarning( "MainWindow::slotSave() not yet implemented!" ); + if (filename == "") + return; + + QFile f(filename); + + if ( !f.open( IO_WriteOnly ) ) + return false; + + QTextStream t(&f); + QString s; + CContact* contact = CContact::getFirst(); + + while ( contact != '\0') + { + t << contact->firstname() << "\n"; + t << contact->lastname() << "\n"; + t << contact->adress() << "\n"; + t << contact->phoneNumber() << "\n"; + contact=contact->getNext(); + } + f.close(); } /* * public slot @@ -51,12 +71,14 @@ void MainWindow::slotDel() */ void MainWindow::slotLoad() { - QString filename(QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this)); - cout << "Funkar"; + slotSave(); QFile f(filename); - if ( !f.open( IO_ReadOnly ) ) - return; - + do + { + filename(QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this)); + } + while ( !f.open( IO_ReadOnly ) ); + QTextStream t(&f); while (!t.eof()) @@ -79,7 +101,10 @@ void MainWindow::slotSearch() qWarning( "MainWindow::slotSearch() not yet implemented!" ); } - +void slotModify(QListViewItem* lvi) +{ + qWarning( "MainWindow::slotModif(QListViewItem*) not yet implemented!" ); +} /* * This funtion puts all contacts in the listview */ diff --git a/mainwindow.h b/mainwindow.h index 4bb69de..8eca343 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -16,9 +16,11 @@ public slots: void slotDel(); void slotLoad(); void slotSearch(); - + void slotModify(QListViewItem* lvi); protected: void updateView(); + + QString filename; }; #endif // MAINWINDOW_H -- 2.39.2