X-Git-Url: https://ruin.nu/git/?p=adress.git;a=blobdiff_plain;f=mainwindow.cpp;h=f07283884ccbb285d906bbc5b305dd0c7a7f8fcc;hp=ce83c8cae5d1f6b7baa8638b04c60dfe53cb3476;hb=4afecc26047eac097df5debb682e8fe2eb21f26d;hpb=92e3acb55da7ab30dc485ae5a349000b2f91f59c diff --git a/mainwindow.cpp b/mainwindow.cpp index ce83c8c..f072838 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,8 @@ #include "mainwindow.h" #include +#include "contactmodifyer.h" + /* BRÖÖL * Constructs a MainWindow which is a child of 'parent', with the * name 'name' and widget flags set to 'f' @@ -56,14 +58,40 @@ 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 @@ -105,7 +133,56 @@ void MainWindow::slotSearch() 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