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.setQuery("SELECT * FROM server_notifications WHERE complete='0'", bdb); //LIMIT 1
liczbaWiadomosci = queryModel.rowCount();
bdb.close();
out << "Mamy: " << liczbaWiadomosci << " wiadomosci!" << endl;
for(int i=0 ; i<liczbaWiadomosci; i++)
{
rec = queryModel.record(i);
out << rec.value(1).toString() << ": ";
out << rec.value(2).toString() << endl;
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);
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();
bdb.close();
delete query;
}
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.setQuery("SELECT * FROM config WHERE name='qt-notification-interval'", bdb);
rec = queryModel.record(0);
notificationInterval = (rec.value(1).toInt())*1000;
out << "Notification interval: " << notificationInterval << " ms" << endl;
bdb.close();
return ok;
}
bool MainWindow::pobierzKomunikaty()
{
bool ok;
QTextStream out(stdout);
QString zapytanie;
QSqlRecord rec;
QSqlQueryModel queryModel;
QFont font;
font.setPointSize(7);
odczytanoOstatnieKomunikaty=0;
ok = bdb.open();
if (ok)
{
out << endl << "Otworzylem baze!" << endl ;
} else {
out << "Nie udalo sie otworzyc bazy!" << endl;
}
queryModel.setQuery("SELECT * FROM server_notifications WHERE complete='0'", bdb); //LIMIT 1
liczbaWiadomosci = queryModel.rowCount();
bdb.close();
out << "Mamy: " << liczbaWiadomosci << " wiadomosci!" << endl;
for(int i=0 ; i<liczbaWiadomosci; i++)
{
rec = queryModel.record(i);
out << rec.value(1).toString() << ": ";
out << rec.value(2).toString() << endl;
QMessageBox *msgBox=new QMessageBox;
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);
msgBox->setFont(font);
msgBox->setWindowTitle(rec.value(1).toString());
msgBox->setText(rec.value(2).toString());
QSpacerItem* horizontalSpacer = new QSpacerItem(240, 290, QSizePolicy::Minimum, QSizePolicy::Minimum);
QGridLayout* layout = (QGridLayout*)msgBox->layout();
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("'");
QSqlQuery *query=new QSqlQuery;
query->clear();
query->prepare(zapytanie);
ok = query->exec();
bdb.close();
delete query;
}
odczytanoOstatnieKomunikaty=1;
return ok;
}
bool MainWindow::wyswietlKomunikaty()
{
if(odczytanoOstatnieKomunikaty==0)
{
} else
{
pobierzKomunikaty();
odczytajNotificationInterval();
timer->start(notificationInterval);
}
return 1;
}
bool MainWindow::odczytajNotificationInterval()
{
bool ok;
QTextStream out(stdout);
QSqlRecord rec;
QSqlQueryModel queryModel;
ok = bdb.open();
if (ok)
{
out << endl << "Otworzylem baze!" << endl ;
} else {
out << "Nie udalo sie otworzyc bazy!" << endl;
}
queryModel.setQuery("SELECT * FROM config WHERE name='qt-notification-interval'", bdb);
rec = queryModel.record(0);
notificationInterval = (rec.value(1).toInt())*1000;
out << "Notification interval: " << notificationInterval << " ms" << endl;
bdb.close();
return ok;
}
To copy to clipboard, switch view to plain text mode
Bookmarks