bool MainWindow::pobierzKomunikaty()
{
bool ok;
font.setPointSize(7);
odczytanoOstatnieKomunikaty=0;
ok = bdb.open();
if (ok)
{
out << endl << "Otworzylem baze!" << endl ;
} else {
out << "Nie udalo sie otworzyc bazy!" << endl;
}
queryModel.clear();
queryModel.setQuery("SELECT * FROM server_notifications WHERE complete='0'", bdb);
liczbaWiadomosci = queryModel.rowCount();
bdb.close();
#ifdef DEBUG
out << "Mamy: " << liczbaWiadomosci << " wiadomosci!" << endl;
#endif
for(int i=0 ; i<liczbaWiadomosci; i++)
{
rec = queryModel.record(i);
#ifdef DEBUG
out << rec.value(1).toString() << ": ";
out << rec.value(2).toString() << endl;
#endif
if(rec.
value(1).
toString()=="warning") msgBox
->setIcon
(QMessageBox::Warning);
else if (rec.
value(1).
toString()=="info") msgBox
->setIcon
(QMessageBox::Information);
else if (rec.
value(1).
toString()=="error") msgBox
->setIcon
(QMessageBox::Critical);
if(rec.value(1).toString()!="confirmation")
{
msgBox->setFont(font);
msgBox->setWindowTitle(rec.value(1).toString());
msgBox->setText(rec.value(2).toString());
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
msgBox->move(0,0);
msgBox->exec();
delete msgBox;
ok = bdb.open();
zapytanie.clear();
zapytanie="update server_notifications set complete='1'";
zapytanie.append(" where id='");
zapytanie.
append(QString::number(rec.
value(0).
toInt()));
zapytanie.append("'");
query.clear();
query.prepare(zapytanie);
ok = query.exec();
query.clear();
bdb.close();
} else if (rec.value(1).toString()=="confirmation") {
msgBox->setFont(font);
msgBox->setWindowTitle(rec.value(1).toString());
msgBox->setText(rec.value(2).toString());
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
msgBox->move(0,0);
int result = msgBox->exec();
delete msgBox;
ok = bdb.open();
zapytanie.clear();
if (result
== QMessageBox::Yes) zapytanie
="update server_notifications set complete='2'";
else if (result
== QMessageBox::No) zapytanie
="update server_notifications set complete='3'";
zapytanie.append(" where id='");
zapytanie.
append(QString::number(rec.
value(0).
toInt()));
zapytanie.append("'");
query.clear();
query.prepare(zapytanie);
ok = query.exec();
query.clear();
bdb.close();
}
}
zapytanie.clear();
rec.clear();
queryModel.clear();
odczytanoOstatnieKomunikaty=1;
return ok;
}
bool MainWindow::wyswietlKomunikaty()
{
if(odczytanoOstatnieKomunikaty==0)
{
} else
{
pobierzKomunikaty();
odczytajNotificationInterval();
timer.start(notificationInterval);
}
return 1;
}
bool MainWindow::odczytajNotificationInterval()
{
bool ok;
ok = bdb.open();
if (ok)
{
out << endl << "Otworzylem baze!" << endl ;
} else {
out << "Nie udalo sie otworzyc bazy!" << endl;
}
queryModel.clear();
queryModel.setQuery("SELECT * FROM config WHERE name='qt-notification-interval'", bdb);
rec = queryModel.record(0);
notificationInterval = (rec.value(1).toInt())*1000;
#ifdef DEBUG
out << "Notification interval: " << notificationInterval << " ms" << endl;
#endif
rec.clear();
queryModel.clear();
bdb.close();
return ok;
}