Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

author.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   author.cpp                                                            *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   Read the file COPYING for details.                                    *
00011  *                                                                         *
00012  *   copyright: (C) 2003 by Jan Mueller                                    *
00013  *   email: janmueller7@hotmail.com                                        *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 #include "author.h"
00018 #include "liturl.h"
00019 #include <qlayout.h>
00020 #include <qtoolbar.h>
00021 #include <qaction.h>
00022 #include <qpixmap.h>
00023 #include <qmessagebox.h>
00024 #include <qlineedit.h>
00025 #include <qlabel.h>
00026 #include <qapplication.h>
00027 #include <qsqldatabase.h>
00028 #include <qsqlcursor.h>
00029 #include <qevent.h>
00030 #include <qlayout.h>
00031 #include <qsettings.h>
00032 #include "error.h"
00033 #include "editorhelper.h"
00034 #include "global.h"
00035 #include "linklistbox.h"
00036 #include "filllinklistbox.h"
00037 #include "mainwindowimpl.h"
00038 #include "selectitem.h"
00039 #include "selectnote.h"
00040 #include "selectpart.h"
00041 
00042 Author::Author(LitUrl url, QObject *receiver, QString slot, MainWindow *parent, const char *name): ReadWriteFormBase(url, receiver, slot, parent, name), toolbar(0L) {    
00043     authorform=new AuthorForm(this, "authorform");
00044     QHBoxLayout *l=new QHBoxLayout(this);
00045     l->addWidget(authorform);
00046     initToolBar();
00047     new EditorHelper(this, authorform->memo);
00048     QSettings settings;
00049     QString backgr = settings.readEntry(QString("/literature/backgr_")+name, "");
00050     if(!backgr.isEmpty()) authorform->setErasePixmap(QPixmap(backgr));
00051 
00052     setData();
00053 }
00054 
00055 void Author::initToolBar() {
00056     toolbar=new QToolBar(mainWindow());
00057     
00058     // **** Note ****
00059     insertNoteAction=new QAction("Insert Note", QIconSet(loadPixmap("insnote.png")), "Insert Note", 0, this, "insertnote");
00060     connect(insertNoteAction, SIGNAL(activated()), this, SLOT(insertNote()));
00061     createNoteAction=new QAction("Create Note", QIconSet(loadPixmap("newnote.png")), "Create Note", 0, this, "createnote");
00062     connect(createNoteAction, SIGNAL(activated()), this, SLOT(createNote()));
00063     deleteNoteAction=new QAction("Delete Note", QIconSet(loadPixmap("delnote.png")), "Delete Note", 0, this, "deletenote");
00064     connect(deleteNoteAction, SIGNAL(activated()), this, SLOT(deleteNote()));
00065     
00066     // **** Publication ****
00067     insertPublicationAction=new QAction("Insert Publication", QIconSet(loadPixmap("inspubl.png")), "Insert Publication", 0, this, "insertpublication");
00068     connect(insertPublicationAction, SIGNAL(activated()), this, SLOT(insertPublication()));
00069     createPublicationAction=new QAction("Create Publication", QIconSet(loadPixmap("newpubl.png")), "Create Publication", 0, this, "createpublication");
00070     connect(createPublicationAction, SIGNAL(activated()), this, SLOT(createPublication()));
00071     deletePublicationAction=new QAction("Delete Publication", QIconSet(loadPixmap("delpubl.png")), "Delete Publication", 0, this, "deletepublication");
00072     connect(deletePublicationAction, SIGNAL(activated()), this, SLOT(deletePublication()));
00073     
00074 
00075     // **** Part ****
00076     insertPartAction=new QAction("Insert Part", QIconSet(loadPixmap("inspart.png")), "Insert Part", 0, this, "insertpart");
00077     connect(insertPartAction, SIGNAL(activated()), this, SLOT(insertPart()));
00078     deletePartAction=new QAction("Delete Part", QIconSet(loadPixmap("delpart.png")), "Delete Part", 0, this, "deletepart");
00079     connect(deletePartAction, SIGNAL(activated()), this, SLOT(deletePart()));
00080 
00081             
00082     insertNoteAction->addTo(toolbar);
00083     createNoteAction->addTo(toolbar);
00084     deleteNoteAction->addTo(toolbar);
00085 
00086     insertPublicationAction->addTo(toolbar);
00087     createPublicationAction->addTo(toolbar);
00088     deletePublicationAction->addTo(toolbar);
00089 
00090     insertPartAction->addTo(toolbar);
00091     deletePartAction->addTo(toolbar);
00092    
00093     toolbar->show();
00094 
00095     insertNoteAction->addTo(roMenu());
00096     createNoteAction->addTo(roMenu());
00097     deleteNoteAction->addTo(roMenu());
00098 
00099     insertPublicationAction->addTo(roMenu());
00100     createPublicationAction->addTo(roMenu());
00101     deletePublicationAction->addTo(roMenu());
00102 
00103     insertPartAction->addTo(roMenu());
00104     deletePartAction->addTo(roMenu());
00105 
00106 
00107 }
00108 
00109 Author::~Author() {
00110     write();
00111     delete toolbar;
00112 
00113 }
00114 
00115 bool Author::setData()
00116 {
00117     try {
00118         ReadWriteFormBase::setData();
00119         LitUrl u=url();
00120         setWorkingGui(true);
00121         form.clear();
00122         formcursor.clear();
00123         formcursor.setMode(QSqlCursor::Writable);
00124         formcursor.setName("author");
00125         if(!formcursor.select(u.query()))
00126             throw(Error(formcursor.lastError()));
00127         qDebug("count:"+QString().setNum(formcursor.size()));
00128         if(formcursor.size()!=1) throw Error("Invalid Record!");
00129         formcursor.first();
00130         QString no=formcursor.value("no").toString();
00131         form.setRecord(formcursor.primeUpdate());
00132         form.insert(authorform->firstname, "firstname");
00133         form.insert(authorform->lastname, "lastname");
00134         form.insert(authorform->pseudonym, "pseudonym");
00135         form.insert(authorform->country, "country");
00136         form.insert(authorform->born, "born");
00137         form.insert(authorform->died, "died");
00138         form.insert(authorform->memo, "memo");
00139         form.insert(authorform->modified, "modified");
00140         form.insert(authorform->created, "created");
00141         form.readFields();
00142 
00143         authorform->links->setEnabled(false);
00144         authorform->publications->setEnabled(false);
00145         authorform->parts->setEnabled(false);
00146         
00147         authorform->publications->clear();
00148         fillpubl=new FillLinkListBox(this, "publauthorfllb", authorform->publications, "select publication.no, publication.title from publication, publication_author where publication.no=publication_author.publication_no and publication_author.author_no="+no+" order by title","publication/publication", loadPixmap("showpubl.png"));
00149         fillpubl->start();
00150         threads.append(fillpubl);
00151 
00152         authorform->parts->clear();
00153         fillpart=new FillLinkListBox(this, "partauthorfllb", authorform->parts, "select part.no, part.title from part, part_author where part.no=part_author.part_no and part_author.author_no="+no+" order by part.title", "part/part", loadPixmap("showpart.png"));
00154         fillpart->start();
00155         threads.append(fillpart);
00156 
00157         authorform->links->clear();
00158         filllink=new FillLinkListBox(this, "linkauthorfllb", authorform->links, "select note.no, note.title from note, link where "+buildLinkWhereClause("note", "author", no)+" order by note.title","note/note", loadPixmap("shownote.png"));
00159         filllink->start();
00160         threads.append(filllink);
00161 
00162         setValid(true);
00163     } catch(Error &e) {
00164         setValid(false);
00165         setReadonlyGui(true);
00166         QMessageBox::warning(this, "Error", e.message());
00167         return false;
00168     }
00169     setValid(true);
00170     return true;
00171 }
00172 
00173 void Author::setWorkingGui(bool work) {
00174     ReadWriteFormBase::setWorkingGui(work);
00175     authorform->links->setEnabled(!work);
00176     authorform->publications->setEnabled(!work);
00177     authorform->parts->setEnabled(!work);
00178 }
00179 
00180 void Author::setReadonlyGui(bool ro) {
00181     debug("Author::setReadonlyGui");
00182     ReadWriteFormBase::setReadonlyGui(ro);    
00183     authorform->firstname->setEnabled(!ro);
00184     authorform->lastname->setEnabled(!ro);
00185     authorform->pseudonym->setEnabled(!ro);
00186     authorform->country->setEnabled(!ro);
00187     authorform->born->setEnabled(!ro);
00188     authorform->died->setEnabled(!ro);
00189     authorform->memo->setEnabled(!ro);
00190  }
00191 
00192 void Author::setInvalidGui(bool inv) {
00193     ReadWriteFormBase::setInvalidGui(inv);
00194     setWorkingGui(false);
00195     setReadonlyGui(inv);
00196 }
00197 
00198 void Author::insertNote() {
00199     SelectNote *s=new SelectNote(this, "selnote");
00200     Q_ASSERT(s);
00201     if(s->exec()==QDialog::Accepted)
00202       createLink(s->url(), url());
00203 }
00204 
00205 void Author::deleteNote() {
00206   deleteLink(authorform->links->url(),url());    
00207 }
00208 
00209 void Author::createNote() {
00210     newNote(url());
00211 }
00212 
00213 void Author::insertPublication() {
00214     SelectItem *s=new SelectItem(this, "selpubls");
00215     Q_ASSERT(s);
00216     s->setData("publication/publication", "select no, title from publication order by title");
00217     if(s->exec()==QDialog::Accepted)
00218       createPublicationAuthor(s->url(), url());
00219 }
00220 
00221 void Author::deletePublication() {
00222     deletePublicationAuthor(authorform->publications->url(),url());
00223 }
00224 
00225 void Author::createPublication() {
00226 }
00227 
00228 void Author::insertPart() {
00229     SelectPart *s=new SelectPart(this, "selpart");
00230     Q_ASSERT(s);
00231     if(s->exec()==QDialog::Accepted)
00232       createPartAuthor(s->url(), url());
00233 }
00234 
00235 void Author::deletePart() {
00236   deletePartAuthor(authorform->parts->url(),url());
00237 }

Generated on Sat Mar 27 19:20:37 2004 for Literature by doxygen 1.3.6-20040222