]> ruin.nu Git - adress.git/blob - mainwindow.cpp
4552b94bf9ea299409901b76f8a61cdce61e8346
[adress.git] / mainwindow.cpp
1 #include "mainwindow.h"
2 #include <iostream>
3
4 /* BRÖÖL
5  *  Constructs a MainWindow which is a child of 'parent', with the 
6  *  name 'name' and widget flags set to 'f' 
7  */
8 MainWindow::MainWindow( QWidget* parent,  const char* name, WFlags fl )
9     : CMainWindowBase( parent, name, fl )
10 {
11         slotLoad();
12 }
13
14 /*  
15  *  Destroys the object and frees any allocated resources
16  */
17 MainWindow::~MainWindow()
18 {
19     // no need to delete child widgets, Qt does it all for us
20 }
21
22 /* 
23  * public slot
24  */
25 void MainWindow::slotSave()
26 {
27         if (filename.isNull())
28         {
29                 filename = QFileDialog::getSaveFileName( 0, "Adresslista (*.adr)");
30                 if (filename.isNull())
31                 {
32                         return;
33                 }
34         }                     
35
36         QFile f(filename);
37
38         if ( !f.open( IO_WriteOnly ) )
39                     return;
40               
41         QTextStream t(&f);
42         QString s;
43         CContact* contact = CContact::getFirst();
44
45         while ( contact != '\0')
46         {
47                 t << contact->firstname() << "\n";
48                 t << contact->lastname() << "\n";
49                 t << contact->adress() << "\n";
50                 t << contact->phoneNumber() << "\n";
51                 contact=contact->getNext();
52         }
53         f.close();
54 }
55 /* 
56  * public slot
57  */
58 void MainWindow::slotAdd()
59 {
60     qWarning( "MainWindow::slotAdd() not yet implemented!" ); 
61 }
62 /* 
63  * public slot
64  */
65 void MainWindow::slotDel()
66 {
67     qWarning( "MainWindow::slotDel() not yet implemented!" ); 
68 }
69 /* 
70  * public slot
71  */
72 void MainWindow::slotLoad()
73 {
74         filename = QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this); 
75
76         QFile f(filename);
77         if ( !f.open( IO_ReadOnly ) )
78                 return;
79                         
80         while (CContact::getNum() != 0)
81         {
82                 delete CContact::getFirst();
83         }
84         
85         QTextStream t(&f);
86
87         while (!t.eof())
88         {
89                 QString fname = t.readLine();
90                 QString lname = t.readLine();
91                 QString adr             = t.readLine();
92                 QString pn              = t.readLine();
93     if (fname == "" && lname == "" && lname == "" && pn == "")
94                               continue;
95                 (void) new CContact(fname, lname, adr, pn);
96         }
97         updateView();
98 }
99 /* 
100  * public slot
101  */
102 void MainWindow::slotSearch()
103 {
104     qWarning( "MainWindow::slotSearch() not yet implemented!" ); 
105 }
106
107 void slotModify(QListViewItem* lvi)
108 {
109     qWarning( "MainWindow::slotModif(QListViewItem*) not yet implemented!" ); 
110 }
111 /*
112  * This funtion puts all contacts in the listview
113  */
114 void MainWindow::updateView()
115 {
116         
117         ContactView->clear();
118
119         CContact* contact = CContact::getFirst();
120
121         int i = 1;
122         char s[100];
123
124         while (contact != '\0')
125         {
126                 sprintf(s,"%i",i);//.arg(i);
127                 (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber());
128                 contact = contact->getNext();
129                 i++;
130         }
131 }