X-Git-Url: https://ruin.nu/git/?p=adress.git;a=blobdiff_plain;f=mainwindow.cpp;h=4552b94bf9ea299409901b76f8a61cdce61e8346;hp=aff0deaffe6d3b5cc197bc0d0fa67c63cd2d66a6;hb=7d9ac6d07bdb73b8ebce6b56cafd6e473b7086b1;hpb=b7d164a2b66c8ce4c416798dc586c24c89473096 diff --git a/mainwindow.cpp b/mainwindow.cpp index aff0dea..4552b94 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,20 +1,14 @@ #include "mainwindow.h" -#include -#include -#include -#include -#include -#include "contact.h" #include -/* +/* BRÖÖL * Constructs a MainWindow which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) : CMainWindowBase( parent, name, fl ) { - //connect(LoadButton, SIGNAL(clicked()), SLOT(slotLoad())); + slotLoad(); } /* @@ -30,7 +24,33 @@ MainWindow::~MainWindow() */ void MainWindow::slotSave() { - qWarning( "MainWindow::slotSave() not yet implemented!" ); + if (filename.isNull()) + { + filename = QFileDialog::getSaveFileName( 0, "Adresslista (*.adr)"); + if (filename.isNull()) + { + return; + } + } + + QFile f(filename); + + if ( !f.open( IO_WriteOnly ) ) + return; + + 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,11 +71,16 @@ void MainWindow::slotDel() */ void MainWindow::slotLoad() { - QString filename(QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this)); - cout << "Funkar"; + filename = QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this); + QFile f(filename); if ( !f.open( IO_ReadOnly ) ) - return; + return; + + while (CContact::getNum() != 0) + { + delete CContact::getFirst(); + } QTextStream t(&f); @@ -79,7 +104,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 */