X-Git-Url: https://ruin.nu/git/?p=adress.git;a=blobdiff_plain;f=mainwindow.cpp;h=69131c7eb461414b489ba474135557dd62d7eb95;hp=aff0deaffe6d3b5cc197bc0d0fa67c63cd2d66a6;hb=refs%2Fheads%2Forigin;hpb=b7d164a2b66c8ce4c416798dc586c24c89473096 diff --git a/mainwindow.cpp b/mainwindow.cpp index aff0dea..69131c7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,20 +1,16 @@ #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' */ MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) : CMainWindowBase( parent, name, fl ) { - //connect(LoadButton, SIGNAL(clicked()), SLOT(slotLoad())); } /* @@ -30,32 +26,89 @@ 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 */ 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() { - 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); @@ -66,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(); @@ -76,10 +129,67 @@ 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 MainWindow::slotModify(QListViewItem* lvi) +{ + 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 */