+++ /dev/null
-#include <fstream>
-#include <string>
-#include "functions.h"
-#include <iostream>
-
-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();
-}
MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
: CMainWindowBase( parent, name, fl )
{
- //connect(LoadButton, SIGNAL(clicked()), SLOT(slotLoad()));
+ slotLoad();
}
/*
*/
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
*/
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())
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
*/