00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "project.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 <qtextedit.h>
00032 #include "error.h"
00033 #include "global.h"
00034 #include "mainwindowimpl.h"
00035 #include "projectform.h"
00036 #include "selectitem.h"
00037 #include "generatebibtex.h"
00038 #include "filllinklistbox.h"
00039 #include "linklistbox.h"
00040 #include "selectpart.h"
00041
00042 Project::Project(LitUrl url, QObject *receiver, QString slot, MainWindow *parent, const char *name): ReadWriteFormBase(url, receiver, slot, parent, name) {
00043 projectform=new ProjectForm(this, "projectform");
00044 QHBoxLayout *l=new QHBoxLayout(this);
00045 l->addWidget(projectform);
00046
00047 QSettings settings;
00048 QString backgr = settings.readEntry(QString("/literature/backgr_")+name, "");
00049 if(!backgr.isEmpty()) projectform->setErasePixmap(QPixmap(backgr));
00050
00051 initToolBar();
00052 setData();
00053 }
00054
00055
00056 void Project::initToolBar() {
00057 toolbar=new QToolBar(mainWindow());
00058
00059 insertPublAction=new QAction("Insert Publication", QIconSet(loadPixmap("inspubl.png")), "Insert Publication", 0, this, "insertpublication");
00060 connect(insertPublAction, SIGNAL(activated()), this, SLOT(insertPublication()));
00061
00062 deletePublAction=new QAction("Delete Publication", QIconSet(loadPixmap("delpubl.png")), "Delete Publication", 0, this, "deletepublication");
00063 connect(deletePublAction, SIGNAL(activated()), this, SLOT(deletePublication()));
00064
00065 insertPartAction=new QAction("Insert Part", QIconSet(loadPixmap("inspart.png")), "Insert Part", 0, this, "insertpart");
00066 connect(insertPartAction, SIGNAL(activated()), this, SLOT(insertPart()));
00067
00068 generateBibTexAction=new QAction("Generate BibTex", QIconSet(loadPixmap("tex.png")), "Generate BibTex", 0, this, "generatebibtex");
00069 connect(generateBibTexAction, SIGNAL(activated()), this, SLOT(generateBibTex()));
00070
00071 insertPublAction->addTo(toolbar);
00072 insertPartAction->addTo(toolbar);
00073 deletePublAction->addTo(toolbar);
00074 generateBibTexAction->addTo(toolbar);
00075 toolbar->show();
00076
00077 insertPublAction->addTo(roMenu());
00078 insertPartAction->addTo(roMenu());
00079 deletePublAction->addTo(roMenu());
00080 generateBibTexAction->addTo(roMenu());
00081
00082 }
00083
00084
00085 Project::~Project() {
00086 write();
00087 delete toolbar;
00088 }
00089
00090 bool Project::setData()
00091 {
00092 try {
00093 ReadWriteFormBase::setData();
00094 LitUrl u=url();
00095 setWorkingGui(true);
00096
00097 form.clear();
00098 formcursor.clear();
00099 formcursor.setMode(QSqlCursor::Writable);
00100 formcursor.setName("project");
00101 if(!formcursor.select(u.query()))
00102 throw(Error(formcursor.lastError()));
00103 if(formcursor.size()!=1) throw Error("Invalid Record!");
00104 formcursor.first();
00105 form.setRecord(formcursor.primeUpdate());
00106 form.insert(projectform->title, "title");
00107 form.insert(projectform->memo, "memo");
00108 form.insert(projectform->modified, "modified");
00109 form.insert(projectform->created, "created");
00110 form.readFields();
00111
00112 projectform->publs->setEnabled(false);
00113 projectform->publs->clear();
00114 fillpubl=new FillLinkListBox(this, "publfllb", projectform->publs, "select publication.no, publication.title from publication, project_bibliography where publication.no=project_bibliography.id_no and project_bibliography.tab_no=tabid('publication') and project_bibliography.project_no="+no(url()), "publication/publication", loadPixmap("showpublication.png"));
00115
00116 fillpubl->start();
00117 threads.append(fillpubl);
00118
00119 fillpart=new FillLinkListBox(this, "partfllb", projectform->publs, "select part.no, part.title||' In: \"'||publication.title||'\"' as title from publication, part, project_bibliography where part.publication_no=publication.no and project_bibliography.id_no=part.no and project_bibliography.tab_no=tabid('part') and project_bibliography.project_no="+no(url()), "part/part", loadPixmap("showpublication.png"));
00120 fillpart->start();
00121 threads.append(fillpart);
00122
00123
00124 fillfile=new FillLinkListBox(this, "filefllb", projectform->publs, "select partdata.no, partdata.filename||' from \"'||part.title||'\" In: \"'||publication.title||'\"' as title from publication, part, partdata, project_bibliography where partdata.part_no=part.no and part.publication_no=publication.no and project_bibliography.id_no=partdata.no and project_bibliography.tab_no=tabid('partdata') and project_bibliography.project_no="+no(url()), "file/partdata", loadPixmap("showpublication.png"));
00125
00126
00127 fillfile->start();
00128 threads.append(fillfile);
00129
00130 setValid(true);
00131 } catch(Error &e) {
00132 setValid(false);
00133 setReadonlyGui(true);
00134 QMessageBox::warning(this, "Error", e.message());
00135 return false;
00136 }
00137 waitForThreads();
00138 setValid(true);
00139
00140 return true;
00141 }
00142
00143 void Project::setWorkingGui(bool work) {
00144 ReadWriteFormBase::setInvalidGui(work);
00145 projectform->publs->setEnabled(!work);
00146 }
00147
00148 void Project::setReadonlyGui(bool ro) {
00149 ReadWriteFormBase::setReadonlyGui(ro);
00150 projectform->publs->setEnabled(!ro);
00151 }
00152
00153 void Project::setInvalidGui(bool inv) {
00154 ReadWriteFormBase::setInvalidGui(inv);
00155 setWorkingGui(false);
00156 setReadonlyGui(inv);
00157 }
00158
00159 void Project::deletePublication() {
00160 write();
00161 LitUrl u=projectform->publs->url();
00162 QSqlQuery q("delete from project_bibliography where project_no="+no(url())+" and tab_no =tabid('"+u.table()+"') and id_no="+no(u));
00163 ASSERT(url().isValid());
00164 if(!setData())
00165 setInvalidGui(true);
00166 }
00167
00168 void Project::generateBibTex() {
00169 GenerateBibTex *g=new GenerateBibTex(this);
00170 g->setProjectNo(no(url()));
00171 g->exec();
00172 }
00173
00174 void Project::insertPublication() {
00175 SelectItem *s=new SelectItem(this, "selpublication");
00176 s->setData("publication/publication", "select publication.no, publication.title from publication order by publication.title");
00177 if(s->exec()==QDialog::Accepted)
00178 createProjectBibliography(url(), s->url());
00179 }
00180
00181 void Project::insertPart() {
00182 SelectPart *s=new SelectPart(this, "selpart");
00183 if(s->exec()==QDialog::Accepted)
00184 createProjectBibliography(url(), s->url());
00185 }