00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "filllinklistbox.h"
00018 #include "linklistbox.h"
00019 #include <qthread.h>
00020 #include <qapplication.h>
00021 #include "linklistboxitem.h"
00022 #include <qsqlcursor.h>
00023 #include <qsqldatabase.h>
00024 #include "dbdata.h"
00025 #include "error.h"
00026 #include <qmessagebox.h>
00027 #include "threadfinishedevent.h"
00028 #include "threadlinkevent.h"
00029
00030 QMutex filllinklistboxmutex;
00031
00032 FillLinkListBox::FillLinkListBox(QObject *parent, QString name, LinkListBox *box, QString query, QString cmd, QPixmap pm, QListViewItem *parentitem): parent(parent), name(name), box(box), query(query), cmd(cmd), pixm(pm), parentitem(parentitem) {
00033 }
00034
00035 FillLinkListBox::~FillLinkListBox() {
00036 }
00037
00038
00039 void FillLinkListBox::run() {
00040 while(filllinklistboxmutex.locked()) {
00041
00042 msleep(10);
00043 }
00044
00045 QMutexLocker locker(&filllinklistboxmutex);
00046
00047
00048 try {
00049
00050 QSqlDatabase *conn=QSqlDatabase::database("threadConnection");
00051 QSqlQuery q(query, conn);
00052 if(!q.isActive())
00053 throw(Error(conn->lastError()));
00054
00055 QSqlRecord r=conn->record(q);
00056 Q_ASSERT(r.position("no")!=-1);
00057 while(q.next()) {
00058 QString str;
00059 for(unsigned int i=0; i<r.count(); i++)
00060 if(r.fieldName(i)!="no")
00061 str+=q.value(i).toString()+" ";
00062
00063 QApplication::postEvent(parent, new ThreadLinkEvent(box, str, LitUrl("lit://"+cmd+"?no="+q.value(r.position("no")).toString()), pixm, parentitem));
00064
00065 }
00066
00067 } catch(Error e) {
00068 qApp->lock();
00069 QMessageBox::warning(0L, "Error", e.message());
00070 qApp->unlock();
00071 }
00072
00073 }