]> ruin.nu Git - adress.git/blobdiff - mainwindow.cpp
It is now possible to add, remove and modify contacts.
[adress.git] / mainwindow.cpp
index ce83c8cae5d1f6b7baa8638b04c60dfe53cb3476..094e54f9156730600c168633283073fa350c3d55 100644 (file)
@@ -1,6 +1,8 @@
 #include "mainwindow.h"
 #include <iostream>
 
+#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,28 @@ 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();
 }
 /*
  * This funtion puts all contacts in the listview