X-Git-Url: https://ruin.nu/git/?p=adress.git;a=blobdiff_plain;f=mainwindow.cpp;h=69131c7eb461414b489ba474135557dd62d7eb95;hp=68afb4353941166251e07141d5a7e1ec3d0c1127;hb=refs%2Fheads%2Forigin;hpb=47556496969ef4c98f36d54c0dd1eac44d2d6caf diff --git a/mainwindow.cpp b/mainwindow.cpp index 68afb43..69131c7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,12 +1,9 @@ #include "mainwindow.h" -#include -#include -#include -#include -#include -#include "contact.h" #include +#include "contactmodifyer.h" +#include "searchresult.h" + /* BRÖÖL * Constructs a MainWindow which is a child of 'parent', with the * name 'name' and widget flags set to 'f' @@ -14,7 +11,6 @@ MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) : CMainWindowBase( parent, name, fl ) { - slotLoad(); } /* @@ -30,13 +26,19 @@ MainWindow::~MainWindow() */ void MainWindow::slotSave() { - if (filename == "") - return; + if (filename.isNull()) + { + filename = QFileDialog::getSaveFileName( 0, "Adresslista (*.adr)"); + if (filename.isNull()) + { + return; + } + } QFile f(filename); if ( !f.open( IO_WriteOnly ) ) - return false; + return; QTextStream t(&f); QString s; @@ -57,28 +59,57 @@ void MainWindow::slotSave() */ void MainWindow::slotAdd() { - qWarning( "MainWindow::slotAdd() not yet implemented!" ); + ContactModifier add; + if(add.exec() == QDialog::Accepted) + updateView(); } /* * public slot */ void MainWindow::slotDel() { - qWarning( "MainWindow::slotDel() not yet implemented!" ); + QListViewItem* lvi = ContactView->selectedItem(); + + if (lvi == '\0') + { + return; + } + + int num = lvi->text(0).toInt(); + + if (num < 1 || num > CContact::getNum()) + return; + + CContact* contact = CContact::getFirst(); + + for (int i = 1; i < num; i++, contact = contact->getNext()) + { + if (contact->getNext() == '\0') + { + return; + } + } + + delete contact; + updateView(); + //qWarning( "MainWindow::slotDel() not yet implemented!" ); } /* * public slot */ void MainWindow::slotLoad() { - slotSave(); + filename = QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this); + QFile f(filename); - do + if ( !f.open( IO_ReadOnly ) ) + return; + + while (CContact::getNum() != 0) { - filename(QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this)); + delete CContact::getFirst(); } - while ( !f.open( IO_ReadOnly ) ); - + QTextStream t(&f); while (!t.eof()) @@ -88,7 +119,7 @@ void MainWindow::slotLoad() QString adr = t.readLine(); QString pn = t.readLine(); if (fname == "" && lname == "" && lname == "" && pn == "") - continue; + continue; (void) new CContact(fname, lname, adr, pn); } updateView(); @@ -98,12 +129,66 @@ void MainWindow::slotLoad() */ void MainWindow::slotSearch() { - qWarning( "MainWindow::slotSearch() not yet implemented!" ); + if (SearchLine->text().isNull()) + return; + + SearchResult search(SearchLine->text(), SearchCombo->currentItem() + 1); + search.show(); + updateView(); } -void slotModify(QListViewItem* lvi) +void MainWindow::slotModify(QListViewItem* lvi) { - qWarning( "MainWindow::slotModif(QListViewItem*) not yet implemented!" ); + if (lvi == '\0') + { + return; + } + + int num = lvi->text(0).toInt(); + + if (num < 1 || num > CContact::getNum()) + return; + + CContact* contact = CContact::getFirst(); + + for (int i = 1; i < num; i++, contact = contact->getNext()) + { + if (contact->getNext() == '\0') + { + return; + } + } + ContactModifier modify(contact); + if(modify.exec() == QDialog::Accepted) + updateView(); +} + +void MainWindow::slotModify() +{ + QListViewItem* lvi = ContactView->selectedItem(); + + if (lvi == '\0') + { + return; + } + + int num = lvi->text(0).toInt(); + + if (num < 1 || num > CContact::getNum()) + return; + + CContact* contact = CContact::getFirst(); + + for (int i = 1; i < num; i++, contact = contact->getNext()) + { + if (contact->getNext() == '\0') + { + return; + } + } + ContactModifier modify(contact); + if(modify.exec() == QDialog::Accepted) + updateView(); } /* * This funtion puts all contacts in the listview