]> ruin.nu Git - adress.git/blob - mainwindow.cpp
Initial revision
[adress.git] / mainwindow.cpp
1 #include "mainwindow.h"
2 #include <qfile.h>
3 #include <qfiledialog.h>
4 #include <qtextstream.h>
5 #include <qstring.h>
6 #include <qlistview.h>
7 #include "contact.h"
8 #include <iostream>
9
10 /* 
11  *  Constructs a MainWindow which is a child of 'parent', with the 
12  *  name 'name' and widget flags set to 'f' 
13  */
14 MainWindow::MainWindow( QWidget* parent,  const char* name, WFlags fl )
15     : CMainWindowBase( parent, name, fl )
16 {
17         //connect(LoadButton, SIGNAL(clicked()), SLOT(slotLoad()));
18 }
19
20 /*  
21  *  Destroys the object and frees any allocated resources
22  */
23 MainWindow::~MainWindow()
24 {
25     // no need to delete child widgets, Qt does it all for us
26 }
27
28 /* 
29  * public slot
30  */
31 void MainWindow::slotSave()
32 {
33     qWarning( "MainWindow::slotSave() not yet implemented!" ); 
34 }
35 /* 
36  * public slot
37  */
38 void MainWindow::slotAdd()
39 {
40     qWarning( "MainWindow::slotAdd() not yet implemented!" ); 
41 }
42 /* 
43  * public slot
44  */
45 void MainWindow::slotDel()
46 {
47     qWarning( "MainWindow::slotDel() not yet implemented!" ); 
48 }
49 /* 
50  * public slot
51  */
52 void MainWindow::slotLoad()
53 {
54         QString filename(QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this)); 
55         cout << "Funkar";
56         QFile f(filename);
57         if ( !f.open( IO_ReadOnly ) )
58                     return;
59         
60         QTextStream t(&f);
61
62         while (!t.eof())
63         {
64                 QString fname = t.readLine();
65                 QString lname = t.readLine();
66                 QString adr             = t.readLine();
67                 QString pn              = t.readLine();
68     if (fname == "" && lname == "" && lname == "" && pn == "")
69                               continue;
70                 (void) new CContact(fname, lname, adr, pn);
71         }
72         updateView();
73 }
74 /* 
75  * public slot
76  */
77 void MainWindow::slotSearch()
78 {
79     qWarning( "MainWindow::slotSearch() not yet implemented!" ); 
80 }
81
82
83 /*
84  * This funtion puts all contacts in the listview
85  */
86 void MainWindow::updateView()
87 {
88         
89         ContactView->clear();
90
91         CContact* contact = CContact::getFirst();
92
93         int i = 1;
94         QString s;
95
96         while (contact != '\0')
97         {
98                 s = i;
99                 (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber());
100                 contact = contact->getNext();
101                 i++;
102         }
103 }