#include "mainwindow.h"
-#include <qfile.h>
-#include <qfiledialog.h>
-#include <qtextstream.h>
-#include <qstring.h>
-#include <qlistview.h>
-#include "contact.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'
MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
: CMainWindowBase( parent, name, fl )
{
- slotLoad();
}
/*
*/
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;
*/
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())
qWarning( "MainWindow::slotSearch() not yet implemented!" );
}
-void slotModify(QListViewItem* lvi)
+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()
{
- qWarning( "MainWindow::slotModif(QListViewItem*) 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;
+ }
+ }
+ ContactModifier modify(contact);
+ if(modify.exec() == QDialog::Accepted)
+ updateView();
}
/*
* This funtion puts all contacts in the listview