From: Michael Andreen Date: Fri, 1 Dec 2000 18:19:12 +0000 (+0000) Subject: Initial revision X-Git-Tag: R1_~1 X-Git-Url: https://ruin.nu/git/?p=adress.git;a=commitdiff_plain;h=e2721b2f5b828bf44923e249832c298972e8413f Initial revision --- e2721b2f5b828bf44923e249832c298972e8413f diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..185dd6b --- /dev/null +++ b/Makefile @@ -0,0 +1,179 @@ +############################################################################# +# Makefile for building adress +# Generated by tmake at 18:07, 2000/12/01 +# Project: adress +# Template: app +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +CFLAGS = -pipe -Wall -W -g3 +CXXFLAGS= -pipe -Wall -W -g3 +INCPATH = -I$(QTDIR)/include +LINK = g++ +LFLAGS = +LIBS = $(SUBLIBS) -L$(QTDIR)/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm +MOC = $(QTDIR)/bin/moc +UIC = $(QTDIR)/bin/uic + +TAR = tar -cf +GZIP = gzip -9f + +####### Files + +HEADERS = contact.h \ + mainwindow.h +SOURCES = contact.cpp \ + main.cpp \ + mainwindow.cpp +OBJECTS = contact.o \ + main.o \ + mainwindow.o \ + ui/contactmodifyerbase.o \ + ui/mainwindowbase.o \ + ui/searchresultbase.o +INTERFACES = ui/contactmodifyerbase.ui \ + ui/mainwindowbase.ui \ + ui/searchresultbase.ui +UICDECLS = ui/contactmodifyerbase.h \ + ui/mainwindowbase.h \ + ui/searchresultbase.h +UICIMPLS = ui/contactmodifyerbase.cpp \ + ui/mainwindowbase.cpp \ + ui/searchresultbase.cpp +SRCMOC = moc_mainwindow.cpp \ + ui/moc_contactmodifyerbase.cpp \ + ui/moc_mainwindowbase.cpp \ + ui/moc_searchresultbase.cpp +OBJMOC = moc_mainwindow.o \ + ui/moc_contactmodifyerbase.o \ + ui/moc_mainwindowbase.o \ + ui/moc_searchresultbase.o +DIST = +TARGET = adress + +####### Implicit rules + +.SUFFIXES: .cpp .cxx .cc .C .c + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< + +####### Build rules + + +all: $(TARGET) + +$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) + +moc: $(SRCMOC) + +tmake: Makefile + +Makefile: adress.pro + tmake adress.pro -o Makefile + +dist: + $(TAR) adress.tar adress.pro $(SOURCES) $(HEADERS) $(INTERFACES) $(DIST) + $(GZIP) adress.tar + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) $(TARGET) + -rm -f *~ core + +####### Sub-libraries + + +###### Combined headers + + +####### Compile + +contact.o: contact.cpp \ + contact.h + +main.o: main.cpp \ + mainwindow.h \ + ui/mainwindowbase.h + +mainwindow.o: mainwindow.cpp \ + mainwindow.h \ + ui/mainwindowbase.h \ + contact.h + +ui/contactmodifyerbase.h: ui/contactmodifyerbase.ui + $(UIC) ui/contactmodifyerbase.ui -o ui/contactmodifyerbase.h + +contactmodifyerbase.h: ui/contactmodifyerbase.ui + $(UIC) ui/contactmodifyerbase.ui -o contactmodifyerbase.h + +ui/contactmodifyerbase.cpp: ui/contactmodifyerbase.ui + $(UIC) ui/contactmodifyerbase.ui -i contactmodifyerbase.h -o ui/contactmodifyerbase.cpp + +ui/mainwindowbase.h: ui/mainwindowbase.ui + $(UIC) ui/mainwindowbase.ui -o ui/mainwindowbase.h + +mainwindowbase.h: ui/mainwindowbase.ui + $(UIC) ui/mainwindowbase.ui -o mainwindowbase.h + +ui/mainwindowbase.cpp: ui/mainwindowbase.ui + $(UIC) ui/mainwindowbase.ui -i mainwindowbase.h -o ui/mainwindowbase.cpp + +ui/searchresultbase.h: ui/searchresultbase.ui + $(UIC) ui/searchresultbase.ui -o ui/searchresultbase.h + +searchresultbase.h: ui/searchresultbase.ui + $(UIC) ui/searchresultbase.ui -o searchresultbase.h + +ui/searchresultbase.cpp: ui/searchresultbase.ui + $(UIC) ui/searchresultbase.ui -i searchresultbase.h -o ui/searchresultbase.cpp + +ui/contactmodifyerbase.o: ui/contactmodifyerbase.cpp \ + ui/contactmodifyerbase.h + +ui/mainwindowbase.o: ui/mainwindowbase.cpp \ + ui/mainwindowbase.h + +ui/searchresultbase.o: ui/searchresultbase.cpp \ + ui/searchresultbase.h + +moc_mainwindow.o: moc_mainwindow.cpp \ + mainwindow.h \ + ui/mainwindowbase.h + +ui/moc_contactmodifyerbase.o: ui/moc_contactmodifyerbase.cpp \ + ui/contactmodifyerbase.h + +ui/moc_mainwindowbase.o: ui/moc_mainwindowbase.cpp \ + ui/mainwindowbase.h + +ui/moc_searchresultbase.o: ui/moc_searchresultbase.cpp \ + ui/searchresultbase.h + +moc_mainwindow.cpp: mainwindow.h + $(MOC) mainwindow.h -o moc_mainwindow.cpp + +ui/moc_contactmodifyerbase.cpp: ui/contactmodifyerbase.h + $(MOC) ui/contactmodifyerbase.h -o ui/moc_contactmodifyerbase.cpp + +ui/moc_mainwindowbase.cpp: ui/mainwindowbase.h + $(MOC) ui/mainwindowbase.h -o ui/moc_mainwindowbase.cpp + +ui/moc_searchresultbase.cpp: ui/searchresultbase.h + $(MOC) ui/searchresultbase.h -o ui/moc_searchresultbase.cpp + diff --git a/adress.pro b/adress.pro new file mode 100644 index 0000000..fd2afb6 --- /dev/null +++ b/adress.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +CONFIG = qt warn_on debug +HEADERS = contact.h \ + mainwindow.h +SOURCES = contact.cpp \ + main.cpp \ + mainwindow.cpp +INTERFACES = ui/contactmodifyerbase.ui \ + ui/mainwindowbase.ui \ + ui/searchresultbase.ui diff --git a/contact.cpp b/contact.cpp new file mode 100644 index 0000000..acda66f --- /dev/null +++ b/contact.cpp @@ -0,0 +1,202 @@ +#include "contact.h" +#include +#include +#include + +CContact* CContact::first = '\0'; +int CContact::num = 0; +/* +QString toLower(QString& s) +{ + QString st = s; + transform(st.begin(), st.end(), st.begin(), tolower); + return st; +}*/ + + +CContact::CContact(QString &firstname, QString &lastname, QString &adress, QString &phonenumber) +{ + strings[0] = firstname; + strings[1] = lastname; + strings[2] = adress; + strings[3] = phonenumber; + + num++; + next = '\0'; + prev = '\0'; + sort(); + +} + +CContact::~CContact() +{ + num--; + remove(); +} + +void CContact::remove() +{ + if (next != '\0' && prev != '\0') + { + next->prev = prev; + prev->next = next; + } + else if (next != '\0' && prev == '\0') + { + next->prev = '\0'; + first = next; + } + else if (next == '\0' && prev != '\0') + { + prev->next = '\0'; + } + else + { + first = '\0'; + } + next = '\0'; + prev = '\0'; +} + +void CContact::sort() +{ + if (first == '\0') + { + first = this; + prev = '\0'; + next = '\0'; + return; + } + CContact* contact = first; + while (contact != '\0') + { + int test = strings[1].upper().compare(contact->strings[1].upper()); + + if (test == 0) + { + //int test2 = strcasecmp(strings[0].c_str(), contact->strings[0].c_str()); + int test2 = strings[0].upper().compare(contact->strings[0].upper()); + + if (test2 < 0) + { + next = contact; + if (first == contact) + { + first = this; + prev = '\0'; + contact->prev = this; + } + else + { + prev = contact->prev; + prev->next = this; + contact->prev = this; + } + break; + } + } + + if (test < 0) + { + next = contact; + if (first == contact) + { + first = this; + prev = '\0'; + contact->prev = this; + } + else + { + prev = contact->prev; + prev->next = this; + contact->prev = this; + } + break; + } + if (contact->next == '\0') + { + prev = contact; + next = '\0'; + contact->next = this; + + break; + } + + contact = contact->next; + } +} + +//Some functions +QString CContact::firstname() +{ + return strings[0]; +} + +QString CContact::lastname() +{ + return strings[1]; +} + +QString CContact::adress() +{ + return strings[2]; +} + +QString CContact::phoneNumber() +{ + return strings[3]; +} + +bool CContact::search(int i, QString s) +{ + if (i > 0 && i < 5) + { + //char* s1 = s.c_str(); + int test = strings[i - 1 ].find(s,0,false ); +// cout << strings[i - 1] << "\n" << s << "\n" << test << "\nTryck Enter"; +// cin.get(); + if (test == 0) //QString::npos) //4294967295) + return true; + else + return false; + } + else + return false; +} + +void CContact::modify(int i, QString s) +{ + if (i > 0 && i < 5) + { +// cout << "Modifierar strängen " << i << " med namnet " << strings[0] << " \n"; + strings[i - 1] = s; + if (i == 2) + { + // cout << "Tar bort gammal konfiguration\n"; + remove(); + // cout << "Lägger till den på rätt plats+n"; + sort(); + } + } +} +//Static functions +CContact* CContact::getFirst() +{ + return first; +} + +int CContact::getNum() +{ + return num; +} + + +CContact* CContact::getNext() +{ + return next; +} + +CContact* CContact::getPrev() +{ + return prev; +} diff --git a/contact.h b/contact.h new file mode 100644 index 0000000..3f16e26 --- /dev/null +++ b/contact.h @@ -0,0 +1,41 @@ +#ifndef __contacth__ +#define __contacth__ + +#include +#include +#include + +class CContact +{ +public: + CContact(QString &firstname, QString &lastname, QString &adress, QString &phonenumber); + ~CContact(); + + QString firstname(); + QString lastname(); + QString adress(); + QString phoneNumber(); + + bool search(int i, QString s); + void modify(int i, QString s); + + //Static funktions + static CContact* getFirst(); + static int getNum(); + + CContact* getNext(); + CContact* getPrev(); + + +protected: + QString strings[4]; + + //Linked list + static CContact* first; + static int num; + CContact* next; + CContact* prev; + void sort(); + void remove(); +}; +#endif diff --git a/file.cpp b/file.cpp new file mode 100644 index 0000000..86e57d1 --- /dev/null +++ b/file.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "functions.h" +#include + +void load() +{ + ifstream in("/root/.adress"); + + while (!in.eof()) + { + string fname; + string lname; + string adr; + string pn; + getline(in, fname); +// cout << "Skapar " << fname << "\n"; +// cin.get(); + getline(in, lname); + getline(in, adr); + getline(in, pn); + if (fname == "" && lname == "" && lname == "" && pn == "") + continue; + (void) new CContact(fname, lname, adr, pn); + } +} + +void save() +{ + ofstream out; + out.open("/root/.adress"); + + CContact* contact = CContact::getFirst(); + + while ( contact != '\0') + { + out << contact->firstname() << "\n"; + out << contact->lastname() << "\n"; + out << contact->adress() << "\n"; + out << contact->phoneNumber() << "\n"; + contact=contact->getNext(); + } + out.close(); +} diff --git a/functions.h b/functions.h new file mode 100644 index 0000000..afb6972 --- /dev/null +++ b/functions.h @@ -0,0 +1,16 @@ +#ifndef __functions_h__ +#define __functions_h__ +#include "contact.h" + +void display(); +void add(); +void remove(); +void printContactInfo(int num, CContact* contact); +void search(); + +void save(); +void load(); + +void modify(); + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..89376c3 --- /dev/null +++ b/main.cpp @@ -0,0 +1,31 @@ + +#include +#include +#include +#include +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + //a.setFont(QFont("helvetica", 12)); + //QTranslator tor( 0 ); + // set the location where your .qm files are in load() below as the last parameter instead of "." + // for development, use "/" to use the english original as + // .qm files are stored in the base project directory. + //tor.load( QString("|.") + QTextCodec::locale(), "." ); + //a.installTranslator( &tor ); + /* uncomment the following line, if you want a Windows 95 look*/ + // a.setStyle(WindowsStyle); + + MainWindow* mw=new MainWindow(); + a.setMainWidget(mw); + + mw->show(); + + return a.exec(); +} + + diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..34c431e --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,103 @@ +#include "mainwindow.h" +#include +#include +#include +#include +#include +#include "contact.h" +#include + +/* + * 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 ) +{ + //connect(LoadButton, SIGNAL(clicked()), SLOT(slotLoad())); +} + +/* + * Destroys the object and frees any allocated resources + */ +MainWindow::~MainWindow() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * public slot + */ +void MainWindow::slotSave() +{ + qWarning( "MainWindow::slotSave() not yet implemented!" ); +} +/* + * public slot + */ +void MainWindow::slotAdd() +{ + qWarning( "MainWindow::slotAdd() not yet implemented!" ); +} +/* + * public slot + */ +void MainWindow::slotDel() +{ + qWarning( "MainWindow::slotDel() not yet implemented!" ); +} +/* + * public slot + */ +void MainWindow::slotLoad() +{ + QString filename(QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this)); + cout << "Funkar"; + QFile f(filename); + if ( !f.open( IO_ReadOnly ) ) + return; + + QTextStream t(&f); + + while (!t.eof()) + { + QString fname = t.readLine(); + QString lname = t.readLine(); + QString adr = t.readLine(); + QString pn = t.readLine(); + if (fname == "" && lname == "" && lname == "" && pn == "") + continue; + (void) new CContact(fname, lname, adr, pn); + } + updateView(); +} +/* + * public slot + */ +void MainWindow::slotSearch() +{ + qWarning( "MainWindow::slotSearch() not yet implemented!" ); +} + + +/* + * This funtion puts all contacts in the listview + */ +void MainWindow::updateView() +{ + + ContactView->clear(); + + CContact* contact = CContact::getFirst(); + + int i = 1; + QString s; + + while (contact != '\0') + { + s = i; + (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber()); + contact = contact->getNext(); + i++; + } +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..4bb69de --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,24 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H +#include "ui/mainwindowbase.h" + +class MainWindow : public CMainWindowBase +{ + Q_OBJECT + +public: + MainWindow( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~MainWindow(); + +public slots: + void slotSave(); + void slotAdd(); + void slotDel(); + void slotLoad(); + void slotSearch(); + +protected: + void updateView(); +}; + +#endif // MAINWINDOW_H diff --git a/ui/contactmodifyerbase.ui b/ui/contactmodifyerbase.ui new file mode 100644 index 0000000..47f8536 --- /dev/null +++ b/ui/contactmodifyerbase.ui @@ -0,0 +1,263 @@ + +ContactModifierBase +Michael Andreen + + QDialog + + name + MyDialog + + + geometry + + 0 + 0 + 538 + 201 + + + + caption + Lägg till kontakt + + + sizeGripEnabled + true + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout10 + + + + margin + 0 + + + spacing + 6 + + + QPushButton + + name + buttonOk + + + text + &OK + + + autoDefault + true + + + default + true + + + + + name + Spacer1 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + buttonCancel + + + text + &Cancel + + + autoDefault + true + + + + + + QLayoutWidget + + name + Layout13 + + + + margin + 0 + + + spacing + 6 + + + QLayoutWidget + + name + Layout12 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + TextLabel1 + + + text + &Förnamn + + + buddy + FirstnameLine + + + + QLabel + + name + TextLabel2 + + + text + &Efternamn + + + buddy + LastnameLine + + + + QLabel + + name + TextLabel3 + + + text + &Adress + + + buddy + AdressLine + + + + QLabel + + name + TextLabel4 + + + text + &Telefonnummer + + + buddy + PhoneNumberLine + + + + + + QLayoutWidget + + name + Layout11 + + + + margin + 0 + + + spacing + 6 + + + QLineEdit + + name + FirstnameLine + + + + QLineEdit + + name + LastnameLine + + + + QLineEdit + + name + AdressLine + + + + QLineEdit + + name + PhoneNumberLine + + + + + + + + + + + buttonOk + clicked() + MyDialog + accept() + + + buttonCancel + clicked() + MyDialog + reject() + + + diff --git a/ui/mainwindowbase.ui b/ui/mainwindowbase.ui new file mode 100644 index 0000000..dc56395 --- /dev/null +++ b/ui/mainwindowbase.ui @@ -0,0 +1,385 @@ + +CMainWindowBase +Michael Andreen + + QWidget + + name + unnamed + + + geometry + + 0 + 0 + 542 + 398 + + + + caption + Form1 + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout4 + + + + margin + 0 + + + spacing + 6 + + + QListView + + + text + Num + + + clickable + true + + + resizeable + true + + + + + text + Efternamn + + + clickable + true + + + resizeable + true + + + + + text + Förnamn + + + clickable + true + + + resizeable + true + + + + + text + Adress + + + clickable + true + + + resizeable + true + + + + + text + Telefonnummer + + + clickable + true + + + resizeable + true + + + + name + ContactView + + + + QLayoutWidget + + name + Layout3 + + + + margin + 0 + + + spacing + 6 + + + QPushButton + + name + LoadButton + + + text + &Ladda fil + + + + QPushButton + + name + SaveButton + + + text + &Spara + + + + + name + Spacer1 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + AddButton + + + text + &Ny kontakt + + + + QPushButton + + name + DelButton + + + text + &Ta bort + + + + + + + + QGroupBox + + name + GroupBox1 + + + title + GroupBox1 + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout1 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + TextLabel1 + + + text + Sök &kategori: + + + buddy + SearchCombo + + + + QComboBox + + + text + Förnamn + + + + + text + Efternamn + + + + + text + Adress + + + + + text + Telefonnummer + + + + name + SearchCombo + + + + QPushButton + + name + SearchButton + + + text + S&ök + + + default + true + + + + + + QLayoutWidget + + name + Layout2 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + TextLabel2 + + + text + Sök&ord + + + buddy + SearchLine + + + + QLineEdit + + name + SearchLine + + + + + + + + + + + LoadButton + clicked() + unnamed + slotLoad() + + + SaveButton + clicked() + unnamed + slotSave() + + + AddButton + clicked() + unnamed + slotAdd() + + + DelButton + clicked() + unnamed + slotDel() + + + SearchButton + clicked() + unnamed + slotSearch() + + slotSave() + slotAdd() + slotDel() + slotLoad() + slotSearch() + + diff --git a/ui/searchresultbase.ui b/ui/searchresultbase.ui new file mode 100644 index 0000000..82b2394 --- /dev/null +++ b/ui/searchresultbase.ui @@ -0,0 +1,278 @@ + +SearchResultBase +Michael Andreen + + QDialog + + name + MyDialog + + + geometry + + 0 + 0 + 515 + 286 + + + + caption + Sökresultat + + + sizeGripEnabled + true + + + + margin + 11 + + + spacing + 6 + + + QListView + + + text + Num + + + clickable + true + + + resizeable + true + + + + + text + Efternamn + + + clickable + true + + + resizeable + true + + + + + text + Förnamn + + + clickable + true + + + resizeable + true + + + + + text + Adress + + + clickable + true + + + resizeable + true + + + + + text + Telefonnummer + + + clickable + true + + + resizeable + true + + + + name + ContactView + + + + QLayoutWidget + + name + Layout15 + + + + margin + 0 + + + spacing + 6 + + + QPushButton + + name + buttonOk + + + text + &OK + + + autoDefault + true + + + default + true + + + + + name + Horizontal Spacing2 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + buttonCancel + + + text + &Cancel + + + autoDefault + true + + + + + + QLayoutWidget + + name + Layout17 + + + + margin + 0 + + + spacing + 6 + + + + name + Spacer3 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + DelButton + + + text + &Ta bort + + + + + name + Spacer4 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + + + + + buttonOk + clicked() + MyDialog + accept() + + + buttonCancel + clicked() + MyDialog + reject() + + + DelButton + clicked() + MyDialog + slotDel() + + slotDel() + +