00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "publication.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 <qcombobox.h>
00031 #include <qsettings.h>
00032 #include <qlayout.h>
00033 #include <qpushbutton.h>
00034 #include "error.h"
00035 #include "editorhelper.h"
00036 #include "global.h"
00037 #include "linklistbox.h"
00038 #include "authorlinklistbox.h"
00039 #include "filllinklistbox.h"
00040 #include "mainwindowimpl.h"
00041 #include "urlevent.h"
00042 #include "selectnote.h"
00043 #include "selectpart.h"
00044 #include "selectitem.h"
00045 #include "bibtextypes.h"
00046 #include <qvaluelist.h>
00047
00048 Publication::Publication(LitUrl url, QObject *receiver, QString slot, MainWindow *parent, const char *name): ReadWriteFormBase(url, receiver, slot, parent, name), toolbar(0L) {
00049 publform=new PublicationForm(this, "publform");
00050 QHBoxLayout *l=new QHBoxLayout(this);
00051 l->addWidget(publform);
00052
00053 connect(publform->chooseJournal, SIGNAL(clicked()), this, SLOT(chooseJournal()));
00054 connect(publform->choosePublisher, SIGNAL(clicked()), this, SLOT(choosePublisher()));
00055 connect(publform->bibtype, SIGNAL(activated(int)), this, SLOT(checkJournal()));
00056
00057 QSettings settings;
00058 QString backgr = settings.readEntry(QString("/literature/backgr_")+name, "");
00059 if(!backgr.isEmpty()) publform->setErasePixmap(QPixmap(backgr));
00060
00061 initToolBar();
00062 new EditorHelper(this, publform->memo);
00063 setData();
00064 }
00065
00066 void Publication::initToolBar() {
00067 toolbar=new QToolBar(mainWindow());
00068
00069 showBiblioAction=new QAction("Show Bibliography", QIconSet(loadPixmap("showbiblio.png")), "Show Bibliography", 0, this, "showbiblio");
00070 connect(showBiblioAction, SIGNAL(activated()), this, SLOT(showBiblio()));
00071
00072
00073
00074 insertNoteAction=new QAction("Insert Note", QIconSet(loadPixmap("insnote.png")), "Insert Note", 0, this, "insertnote");
00075 connect(insertNoteAction, SIGNAL(activated()), this, SLOT(insertNote()));
00076
00077 createNoteAction=new QAction("Create Note", QIconSet(loadPixmap("newnote.png")), "Create Note", 0, this, "createnote");
00078 connect(createNoteAction, SIGNAL(activated()), this, SLOT(createNote()));
00079
00080 deleteNoteAction=new QAction("Delete Note", QIconSet(loadPixmap("delnote.png")), "Delete Note", 0, this, "deletenote");
00081 connect(deleteNoteAction, SIGNAL(activated()), this, SLOT(deleteNote()));
00082
00083
00084 insertAuthorAction=new QAction("Insert Author", QIconSet(loadPixmap("insauthor.png")), "Insert Author", 0, this, "insertpublication");
00085 connect(insertAuthorAction, SIGNAL(activated()), this, SLOT(insertAuthor()));
00086 createAuthorAction=new QAction("Create Author", QIconSet(loadPixmap("newauthor.png")), "Create Author", 0, this, "createpublication");
00087 connect(createAuthorAction, SIGNAL(activated()), this, SLOT(createAuthor()));
00088 deleteAuthorAction=new QAction("Delete Author", QIconSet(loadPixmap("delauthor.png")), "Delete Author", 0, this, "deletepublication");
00089 connect(deleteAuthorAction, SIGNAL(activated()), this, SLOT(deleteAuthor()));
00090
00091
00092 createPartAction=new QAction("Create Part", QIconSet(loadPixmap("newpart.png")), "Create Part", 0, this, "createpart");
00093 connect(createPartAction, SIGNAL(activated()), this, SLOT(createPart()));
00094
00095 deletePartAction=new QAction("Delete Part", QIconSet(loadPixmap("delpart.png")), "Delete Part", 0, this, "deletepart");
00096 connect(deletePartAction, SIGNAL(activated()), this, SLOT(deletePart()));
00097
00098 addToProjectAction=new QAction("Add to Project", QIconSet(loadPixmap("gnome-folder.png")), "Add to Project", 0, this, "addtoproject");
00099 connect(addToProjectAction, SIGNAL(activated()), this, SLOT(addToProject()));
00100
00101
00102 showBiblioAction->addTo(toolbar);
00103
00104 insertNoteAction->addTo(toolbar);
00105 createNoteAction->addTo(toolbar);
00106 deleteNoteAction->addTo(toolbar);
00107
00108 insertAuthorAction->addTo(toolbar);
00109 createAuthorAction->addTo(toolbar);
00110 deleteAuthorAction->addTo(toolbar);
00111
00112 createPartAction->addTo(toolbar);
00113 deletePartAction->addTo(toolbar);
00114
00115 addToProjectAction->addTo(toolbar);
00116
00117 toolbar->show();
00118
00119 showBiblioAction->addTo(roMenu());
00120
00121 insertNoteAction->addTo(roMenu());
00122 createNoteAction->addTo(roMenu());
00123 deleteNoteAction->addTo(roMenu());
00124
00125 insertAuthorAction->addTo(roMenu());
00126 createAuthorAction->addTo(roMenu());
00127 deleteAuthorAction->addTo(roMenu());
00128
00129 createPartAction->addTo(roMenu());
00130 deletePartAction->addTo(roMenu());
00131
00132 addToProjectAction->addTo(roMenu());
00133 }
00134
00135 void Publication::write() {
00136 ReadWriteFormBase::write();
00137 if(!publform->authors->modified()) return;
00138 typedef QValueList<LitUrl> List;
00139 List l=publform->authors->authorPos();
00140
00141 List::iterator it;
00142 int i=0;
00143 for ( it = l.begin(); it != l.end(); ++it ) {
00144 QString n=no(*it);
00145 QSqlQuery("update publication_author set author_order="+QString().setNum(i)+" where publication_no="+no(url())+" and author_no="+n);
00146 i++;
00147 }
00148 }
00149
00150 Publication::~Publication() {
00151 write();
00152 delete toolbar;
00153 }
00154
00155 void Publication::chooseJournal() {
00156 SelectItem *s=new SelectItem(this, "seljournal");
00157 Q_ASSERT(s);
00158 s->setData("journal/journal", "select no, name from journal order by name");
00159 if(s->exec()==QDialog::Accepted) {
00160 QSqlRecord *rec=formcursor.primeUpdate();
00161 rec->setValue("journal_no", no(s->url()));
00162
00163 publform->journal->setText(s->text());
00164 debug(s->url());
00165 }
00166 }
00167
00168 void Publication::choosePublisher() {
00169 SelectItem *s=new SelectItem(this, "selpublisher");
00170 Q_ASSERT(s);
00171 s->setData("publisher/publisher", "select no, name from publisher order by name");
00172 if(s->exec()==QDialog::Accepted) {
00173 QSqlRecord *rec=formcursor.primeUpdate();
00174 rec->setValue("publisher_no", no(s->url()));
00175
00176
00177 publform->publisher->setText(s->text());
00178 }
00179 }
00180
00181 bool Publication::setData()
00182 {
00183 try {
00184 ReadWriteFormBase::setData();
00185 LitUrl u=url();
00186 setWorkingGui(true);
00187
00188 int i;
00189 publform->bibtype->clear();
00190 for(i=0; i<bibtextypecount; i++)
00191 publform->bibtype->insertItem(bibtexnames[i]);
00192
00193 form.clear();
00194 formcursor.clear();
00195 formcursor.setMode(QSqlCursor::Writable);
00196 formcursor.setName("publication");
00197 if(!formcursor.select(u.query()))
00198 throw(Error(formcursor.lastError()));
00199 qDebug("count:"+QString().setNum(formcursor.size()));
00200 if(formcursor.size()!=1) throw Error("Invalid Record!");
00201 formcursor.first();
00202 QString no=formcursor.value("no").toString();
00203 form.setRecord(formcursor.primeUpdate());
00204 form.insert(publform->title, "title");
00205 form.insert(publform->year, "year");
00206 form.insert(publform->bibtype, "entrytype");
00207 form.insert(publform->memo, "memo");
00208 form.insert(publform->modified, "modified");
00209 form.insert(publform->created, "created");
00210 form.readFields();
00211
00212 checkJournal();
00213
00214
00215
00216
00217 QString journal=formcursor.value("journal_no").toString();
00218 QString publisher=formcursor.value("publisher_no").toString();
00219
00220 QSqlQuery query("select journal.name from journal where no="+journal);
00221 if(query.first())
00222 publform->journal->setText(query.value(0).toString());
00223
00224 query.exec("select publisher.name from publisher where no="+publisher);
00225 if(query.first())
00226 publform->publisher->setText(query.value(0).toString());
00227
00228
00229 publform->links->setEnabled(false);
00230 publform->authors->setEnabled(false);
00231 publform->parts->setEnabled(false);
00232
00233 publform->authors->clear();
00234 fillauthor=new FillLinkListBox(this, "publauthorfllb", publform->authors, "select author.no, author.firstname, author.lastname from author, publication_author where author.no=publication_author.author_no and publication_author.publication_no="+no+" order by publication_author.author_order desc", "author/author", loadPixmap("showauthor"));
00235 fillauthor->start();
00236 threads.append(fillauthor);
00237
00238 publform->parts->clear();
00239 fillpart=new FillLinkListBox(this, "partpublicationfllb", publform->parts, "select part.no, part.partno || ' - ' || part.title from part, publication where part.publication_no=publication.no and publication.no="+no+" order by part.partno desc","part/part", loadPixmap("showpart.png"));
00240 fillpart->start();
00241 threads.append(fillpart);
00242
00243 publform->links->clear();
00244 filllink=new FillLinkListBox(this, "linkpublicationfllb", publform->links, "select note.no, note.title from note, link where"+buildLinkWhereClause("note", "publication", no), "note/note", loadPixmap("shownote.png"));
00245 filllink->start();
00246 threads.append(filllink);
00247
00248 setValid(true);
00249 } catch(Error &e) {
00250 setValid(false);
00251 setReadonlyGui(true);
00252 QMessageBox::warning(this, "Error", e.message());
00253 return false;
00254 }
00255 waitForThreads();
00256 setValid(true);
00257 return true;
00258 }
00259
00260 void Publication::setWorkingGui(bool work) {
00261 ReadWriteFormBase::setWorkingGui(work);
00262 publform->links->setEnabled(!work);
00263 publform->authors->setEnabled(!work);
00264 publform->parts->setEnabled(!work);
00265
00266 }
00267
00268 void Publication::setReadonlyGui(bool ro) {
00269 ReadWriteFormBase::setReadonlyGui(ro);
00270 publform->title->setEnabled(!ro);
00271 publform->year->setEnabled(!ro);
00272 publform->bibtype->setEnabled(!ro);
00273 publform->memo->setEnabled(!ro);
00274 }
00275
00276 void Publication::setInvalidGui(bool inv) {
00277 ReadWriteFormBase::setInvalidGui(inv);
00278 setWorkingGui(false);
00279 setReadonlyGui(inv);
00280 }
00281
00282 void Publication::showBiblio() {
00283 qApp->postEvent(topLevelWidget(), new UrlEvent(LitUrl("lit://bibliography/publication?no="+formcursor.value("no").toString()), false));
00284 }
00285
00286 void Publication::addToProject() {
00287 SelectItem *s=new SelectItem(this, "selproject");
00288 Q_ASSERT(s);
00289 s->setData("project/project", "select no, title from project order by title");
00290 if(s->exec()==QDialog::Accepted) {
00291 QSqlQuery q("insert into project_bibliography (project_no, tab_no, id_no) values ("+
00292 no(s->url())+",tabid('publication'), "+no(url())+")");
00293 }
00294 }
00295
00296 void Publication::insertNote() {
00297 SelectItem *s=new SelectItem(this, "selnote");
00298 Q_ASSERT(s);
00299 s->setData("note/note", "select no, title from note where publication_no="+no(url())+" order by title");
00300 if(s->exec()==QDialog::Accepted)
00301 createLink(s->url(), url());
00302 }
00303
00304 void Publication::deleteNote() {
00305 deleteLink(publform->links->url(),url());
00306 }
00307
00308 void Publication::createNote() {
00309 newNote(url());
00310 }
00311
00312 void Publication::insertAuthor() {
00313 SelectItem *s=new SelectItem(this, "selauthor");
00314 Q_ASSERT(s);
00315 s->setData("author/author", "select no, lastname, firstname from author order by lastname");
00316 if(s->exec()==QDialog::Accepted)
00317 createPublicationAuthor(url(), s->url());
00318 }
00319
00320 void Publication::deleteAuthor() {
00321 deletePublicationAuthor(url(), publform->authors->url());
00322 }
00323
00324 void Publication::createAuthor() {
00325 QSqlQuery q("select create_author() as no");
00326 q.first();
00327 LitUrl u("lit://author/author?no="+q.value(0).toString());
00328 createPublicationAuthor(url(), u);
00329 qApp->postEvent(topLevelWidget(), new UrlEvent(u, false));
00330 }
00331
00332 void Publication::createPart() {
00333 QSqlQuery q("select create_part("+no(url())+") as no");
00334 q.first();
00335 LitUrl u("lit://part/part?no="+q.value(0).toString());
00336 qApp->postEvent(topLevelWidget(), new UrlEvent(u, false));
00337 }
00338
00339 void Publication::deletePart() {
00340 if(!publform->parts->currentItem()) return;
00341 if(QMessageBox::information( this, "Literature",
00342 "Do you want to delete the part?",
00343 "&Yes", "&No")!=0) return;
00344
00345 QSqlQuery query( "select del_obj(no) from "+publform->parts->url().table()+" where "+publform->parts->url().query());
00346 query.first();
00347 if(query.value(0).toString()!="true")
00348 QMessageBox::warning(this, "Error", "Can't delete part since records are locked!"+query.value(0).toString());
00349 setData();
00350
00351 }
00352
00353 void Publication::checkJournal() {
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 debug(QString("checkJournal:"+publform->bibtype->currentItem()));
00372 switch(publform->bibtype->currentItem()) {
00373 case BT_JOURNAL:
00374 case BT_ARTICLE:
00375 publform->chooseJournal->setEnabled(true);
00376 break;
00377 default:
00378 publform->chooseJournal->setEnabled(false);
00379 }
00380 }