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

journal.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   journal.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 "journal.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 <qsettings.h>
00031 #include "error.h"
00032 #include "global.h"
00033 #include "mainwindowimpl.h"
00034 #include "selectitem.h"
00035 #include "linklistbox.h"
00036 #include "filllinklistbox.h"
00037 #include "qpushbutton.h"
00038 
00039 Journal::Journal(LitUrl url, QObject *receiver, QString slot, MainWindow *parent, const char *name): ReadWriteFormBase(url, receiver, slot, parent, name) {    
00040     journalform=new JournalForm(this, "journalform");
00041     QHBoxLayout *l=new QHBoxLayout(this);
00042     l->addWidget(journalform);
00043     connect(journalform->choosePublisher, SIGNAL(clicked()), this, SLOT(choosePublisher()));
00044     QSettings settings;
00045     QString backgr = settings.readEntry(QString("/literature/backgr_")+name, "");
00046     if(!backgr.isEmpty()) journalform->setErasePixmap(QPixmap(backgr));
00047 
00048     setData();
00049 }
00050 
00051 
00052 Journal::~Journal() {
00053     write();
00054 }
00055 
00056 bool Journal::setData()
00057 {
00058     try {
00059         ReadWriteFormBase::setData();
00060         LitUrl u=url();
00061         setWorkingGui(true);
00062         
00063         form.clear();
00064         formcursor.clear();
00065         formcursor.setMode(QSqlCursor::Writable);
00066         formcursor.setName("journal");
00067         if(!formcursor.select(u.query()))
00068             throw(Error(formcursor.lastError()));
00069         if(formcursor.size()!=1) throw Error("Invalid Record!");
00070         formcursor.first();
00071         form.setRecord(formcursor.primeUpdate());
00072         form.insert(journalform->jname, "name");        
00073         form.insert(journalform->modified, "modified");
00074         form.insert(journalform->created, "created");
00075         form.readFields();
00076 
00077         QString publisher=formcursor.value("publisher_no").toString();
00078         QSqlQuery query;
00079         query.exec("select publisher.name from publisher where no="+publisher);
00080         if(query.first())
00081           journalform->pname->setText(query.value(0).toString());
00082 
00083         journalform->publications->clear();
00084         fillpubl=new FillLinkListBox(this, "journalpublfllb", journalform->publications, "select publication.no, publication.title from publication where publication.journal_no="+no(url())+" order by publication.title desc", "publication/publication", loadPixmap("showpubl"));
00085         fillpubl->start();
00086         threads.append(fillpubl);
00087 
00088         waitForThreads();
00089         setValid(true);
00090     } catch(Error &e) {
00091         setValid(false);
00092         setReadonlyGui(true);
00093         QMessageBox::warning(this, "Error", e.message());
00094         return false;
00095     }
00096     setValid(true);
00097     return true;
00098 }
00099 
00100 void Journal::setWorkingGui(bool work) {
00101              ReadWriteFormBase::setInvalidGui(work);
00102  }
00103 
00104 void Journal::setReadonlyGui(bool ro) {
00105     ReadWriteFormBase::setReadonlyGui(ro);
00106 }
00107 
00108 void Journal::setInvalidGui(bool inv) {
00109     ReadWriteFormBase::setInvalidGui(inv);      
00110     setWorkingGui(false);
00111     setReadonlyGui(inv);
00112 }
00113 
00114 void Journal::choosePublisher() {
00115   SelectItem *s=new SelectItem(this, "selpublisher");
00116   Q_ASSERT(s);
00117   s->setData("publisher/publisher", "select no, name from publisher order by name");
00118   if(s->exec()==QDialog::Accepted) {
00119     /*
00120     QSqlRecord *rec=formcursor.primeUpdate();
00121     rec->setValue("publisher_no", no(s->url()));
00122     */
00123 
00124     QSqlQuery query("update journal set publisher_no="+no(s->url())+" where no="+no(url()));
00125     journalform->pname->setText(s->text());
00126   }
00127 }

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