X-Git-Url: https://ruin.nu/git/?p=adress.git;a=blobdiff_plain;f=mainwindow.cpp;h=ce83c8cae5d1f6b7baa8638b04c60dfe53cb3476;hp=34c431e11cf94ee3c24fd49732297b5780b76265;hb=92e3acb55da7ab30dc485ae5a349000b2f91f59c;hpb=e2721b2f5b828bf44923e249832c298972e8413f diff --git a/mainwindow.cpp b/mainwindow.cpp index 34c431e..ce83c8c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,20 +1,13 @@ #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())); } /* @@ -30,7 +23,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 +70,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 +103,10 @@ void MainWindow::slotSearch() qWarning( "MainWindow::slotSearch() not yet implemented!" ); } - +void MainWindow::slotModify(QListViewItem* lvi) +{ + qWarning( "MainWindow::slotModif(QListViewItem*) not yet implemented!" ); +} /* * This funtion puts all contacts in the listview */ @@ -91,11 +118,11 @@ void MainWindow::updateView() CContact* contact = CContact::getFirst(); int i = 1; - QString s; + char s[100]; while (contact != '\0') { - s = i; + sprintf(s,"%i",i);//.arg(i); (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber()); contact = contact->getNext(); i++;