Code improvements
This commit is contained in:
parent
29205d0d03
commit
67204433b4
|
@ -158,11 +158,11 @@ void DbQuery::refreshDates(std::tuple<bool, std::unordered_map<int, std::unorder
|
|||
} catch (...) {
|
||||
// failed to convert to integer
|
||||
successful = false;
|
||||
QString err_msg = QString("An error occured while parsing Years from the database");
|
||||
QString err_msg = this->MSG_ERR_PARSING_YMD.arg( this->WORD_YEARS );
|
||||
if ( this->dialog_level > 0 ) {
|
||||
err_msg += QString("\n\nValue responsible for the error:\n%1").arg(Y_query.value(0).toString());
|
||||
err_msg += QString("\n\n%1:\n%2").arg( this->MSG_RESPONSIBLE_VALUE ).arg( Y_query.value(0).toString() );
|
||||
if ( this->dialog_level == 2 ) {
|
||||
err_msg += QString("\n\nDatabase table name:\n%1").arg(tbl);
|
||||
err_msg += QString("\n\n%1:\n%2").arg( this->MSG_TABLE_NAME ).arg( tbl );
|
||||
}
|
||||
}
|
||||
DialogSec::errGeneric( nullptr, err_msg );
|
||||
|
@ -184,11 +184,11 @@ void DbQuery::refreshDates(std::tuple<bool, std::unordered_map<int, std::unorder
|
|||
} catch (...) {
|
||||
// failed to convert to integer
|
||||
successful = false;
|
||||
QString err_msg = QString("An error occured while parsing Months from the database");
|
||||
QString err_msg = this->MSG_ERR_PARSING_YMD.arg( this->WORD_MONTHS );
|
||||
if ( this->dialog_level > 0 ) {
|
||||
err_msg += QString("\n\nValue responsible for the error:\n%1").arg(M_query.value(0).toString());
|
||||
err_msg += QString("\n\n%1:\n%2").arg( this->MSG_RESPONSIBLE_VALUE ).arg( M_query.value(0).toString() );
|
||||
if ( this->dialog_level == 2 ) {
|
||||
err_msg += QString("\n\nDatabase table name:\n%1").arg(tbl);
|
||||
err_msg += QString("\n\n%1:\n%2").arg( this->MSG_TABLE_NAME ).arg( tbl );
|
||||
}
|
||||
}
|
||||
DialogSec::errGeneric( nullptr, err_msg );
|
||||
|
@ -210,11 +210,11 @@ void DbQuery::refreshDates(std::tuple<bool, std::unordered_map<int, std::unorder
|
|||
} catch (...) {
|
||||
// failed to convert to integer
|
||||
successful = false;
|
||||
QString err_msg = QString("An error occured while parsing Days from the database");
|
||||
QString err_msg = this->MSG_ERR_PARSING_YMD.arg( this->WORD_DAYS );
|
||||
if ( this->dialog_level > 0 ) {
|
||||
err_msg += QString("\n\nValue responsible for the error:\n%1").arg(D_query.value(0).toString());
|
||||
err_msg += QString("\n\n%1:\n%2").arg( this->MSG_RESPONSIBLE_VALUE ).arg( D_query.value(0).toString() );
|
||||
if ( this->dialog_level == 2 ) {
|
||||
err_msg += QString("\n\nDatabase table name:\n%1").arg(tbl);
|
||||
err_msg += QString("\n\n%1:\n%2").arg( this->MSG_TABLE_NAME ).arg( tbl );
|
||||
}
|
||||
}
|
||||
DialogSec::errGeneric( nullptr, err_msg );
|
||||
|
@ -1931,7 +1931,7 @@ const bool DbQuery::getGlobalCounts( const QString& web_server, const std::unord
|
|||
successful = false;
|
||||
QString err_msg = "";
|
||||
if ( this->dialog_level == 2 ) {
|
||||
err_msg = "An error occured while processing";
|
||||
err_msg = this->MSG_ERR_PROCESSING;
|
||||
}
|
||||
DialogSec::errGeneric( nullptr, err_msg );
|
||||
break;
|
||||
|
|
|
@ -9,30 +9,29 @@
|
|||
#include <unordered_map>
|
||||
|
||||
|
||||
const QHash<int, QString>
|
||||
FIELDS = {
|
||||
{0, QMessageBox::tr("Warning")},
|
||||
{10,QMessageBox::tr("Protocol")}, {11,QMessageBox::tr("Method")},
|
||||
{12,QMessageBox::tr("URI")}, {13,QMessageBox::tr("Query")}, {14,QMessageBox::tr("Response code")},
|
||||
{15,QMessageBox::tr("Time taken")}, {16,QMessageBox::tr("Bytes sent")}, {17,QMessageBox::tr("Bytes received")},
|
||||
{18,QMessageBox::tr("Referrer")}, {22,QMessageBox::tr("Cookie")},
|
||||
{20,QMessageBox::tr("Client")}, {21,QMessageBox::tr("User-agent")} },
|
||||
MONTHS = {
|
||||
{1, QMessageBox::tr("January")}, {2, QMessageBox::tr("February")}, {3, QMessageBox::tr("March")},
|
||||
{4, QMessageBox::tr("April")}, {5, QMessageBox::tr("May")}, {6, QMessageBox::tr("June")},
|
||||
{7, QMessageBox::tr("July")}, {8, QMessageBox::tr("August")}, {9, QMessageBox::tr("September")},
|
||||
{10,QMessageBox::tr("October")}, {11,QMessageBox::tr("November")}, {12,QMessageBox::tr("December")} },
|
||||
DAYS = {
|
||||
{1, QMessageBox::tr("Sunday")}, {2, QMessageBox::tr("Monday")}, {3, QMessageBox::tr("Tuesday")},
|
||||
{4, QMessageBox::tr("Wednesday")}, {5, QMessageBox::tr("Thursday")}, {6, QMessageBox::tr("Friday")},
|
||||
{7, QMessageBox::tr("Saturday")} };
|
||||
|
||||
|
||||
class DbQuery
|
||||
{
|
||||
public:
|
||||
DbQuery();
|
||||
|
||||
const QHash<int, QString>
|
||||
FIELDS = {
|
||||
{0, QMessageBox::tr("Warning")},
|
||||
{10,QMessageBox::tr("Protocol")}, {11,QMessageBox::tr("Method")},
|
||||
{12,QMessageBox::tr("URI")}, {13,QMessageBox::tr("Query")}, {14,QMessageBox::tr("Response code")},
|
||||
{15,QMessageBox::tr("Time taken")}, {16,QMessageBox::tr("Bytes sent")}, {17,QMessageBox::tr("Bytes received")},
|
||||
{18,QMessageBox::tr("Referrer")}, {22,QMessageBox::tr("Cookie")},
|
||||
{20,QMessageBox::tr("Client")}, {21,QMessageBox::tr("User-agent")} },
|
||||
MONTHS = {
|
||||
{1, QMessageBox::tr("January")}, {2, QMessageBox::tr("February")}, {3, QMessageBox::tr("March")},
|
||||
{4, QMessageBox::tr("April")}, {5, QMessageBox::tr("May")}, {6, QMessageBox::tr("June")},
|
||||
{7, QMessageBox::tr("July")}, {8, QMessageBox::tr("August")}, {9, QMessageBox::tr("September")},
|
||||
{10,QMessageBox::tr("October")}, {11,QMessageBox::tr("November")}, {12,QMessageBox::tr("December")} },
|
||||
DAYS = {
|
||||
{1, QMessageBox::tr("Sunday")}, {2, QMessageBox::tr("Monday")}, {3, QMessageBox::tr("Tuesday")},
|
||||
{4, QMessageBox::tr("Wednesday")}, {5, QMessageBox::tr("Thursday")}, {6, QMessageBox::tr("Friday")},
|
||||
{7, QMessageBox::tr("Saturday")} };
|
||||
|
||||
void setDialogLevel( const int& new_level );
|
||||
|
||||
void setDbPath( const std::string& path );
|
||||
|
@ -98,9 +97,15 @@ public:
|
|||
long& req_count );
|
||||
|
||||
private:
|
||||
QString MSG_ERR_PROCESSING = QMessageBox::tr("An error occured while processing"),
|
||||
MSG_ERR_PROCESSING_DATES = QMessageBox::tr("An error occured while processing dates"),
|
||||
MSG_ERR_UNX_WS = QMessageBox::tr("Unexpected WebServer");
|
||||
const QString MSG_ERR_UNX_WS = QMessageBox::tr("Unexpected WebServer");
|
||||
const QString MSG_ERR_PROCESSING = QMessageBox::tr("An error occured while processing");
|
||||
const QString MSG_ERR_PROCESSING_DATES = QMessageBox::tr("An error occured while processing dates");
|
||||
const QString MSG_ERR_PARSING_YMD = QMessageBox::tr("An error occured while parsing %1 from the database");
|
||||
const QString WORD_YEARS = QMessageBox::tr("Years");
|
||||
const QString WORD_MONTHS = QMessageBox::tr("Months");
|
||||
const QString WORD_DAYS = QMessageBox::tr("Days");
|
||||
const QString MSG_RESPONSIBLE_VALUE = QMessageBox::tr("Value responsible for the error");
|
||||
const QString MSG_TABLE_NAME = QMessageBox::tr("Database table name");
|
||||
|
||||
// quantity of informational dialogs to display
|
||||
int dialog_level = 2; // 0: essential, 1: usefull, 2: explanatory
|
||||
|
@ -110,27 +115,27 @@ private:
|
|||
|
||||
const QHash<QString, QString>
|
||||
LogFields_to_DbFields = {
|
||||
{FIELDS.value(0), "warning"},
|
||||
{FIELDS.value(10), "protocol"},
|
||||
{FIELDS.value(11), "method"},
|
||||
{FIELDS.value(12), "uri"},
|
||||
{FIELDS.value(13), "query"},
|
||||
{FIELDS.value(14), "response"},
|
||||
{FIELDS.value(15), "time_taken"},
|
||||
{FIELDS.value(16), "bytes_sent"},
|
||||
{FIELDS.value(17), "bytes_received"},
|
||||
{FIELDS.value(18), "referrer"},
|
||||
{FIELDS.value(20), "client"},
|
||||
{FIELDS.value(21), "user_agent"},
|
||||
{FIELDS.value(22), "cookie"}
|
||||
{this->FIELDS.value(0), "warning"},
|
||||
{this->FIELDS.value(10), "protocol"},
|
||||
{this->FIELDS.value(11), "method"},
|
||||
{this->FIELDS.value(12), "uri"},
|
||||
{this->FIELDS.value(13), "query"},
|
||||
{this->FIELDS.value(14), "response"},
|
||||
{this->FIELDS.value(15), "time_taken"},
|
||||
{this->FIELDS.value(16), "bytes_sent"},
|
||||
{this->FIELDS.value(17), "bytes_received"},
|
||||
{this->FIELDS.value(18), "referrer"},
|
||||
{this->FIELDS.value(20), "client"},
|
||||
{this->FIELDS.value(21), "user_agent"},
|
||||
{this->FIELDS.value(22), "cookie"}
|
||||
};
|
||||
|
||||
const QHash<QString, int>
|
||||
Months_s2i = {
|
||||
{MONTHS.value(1),1}, {MONTHS.value(2),2}, {MONTHS.value(3),3},
|
||||
{MONTHS.value(4),4}, {MONTHS.value(5),5}, {MONTHS.value(6),6},
|
||||
{MONTHS.value(7),7}, {MONTHS.value(8),8}, {MONTHS.value(9),9},
|
||||
{MONTHS.value(10),10}, {MONTHS.value(11),11}, {MONTHS.value(12),12} };
|
||||
{this->MONTHS.value(1),1}, {this->MONTHS.value(2),2}, {this->MONTHS.value(3),3},
|
||||
{this->MONTHS.value(4),4}, {this->MONTHS.value(5),5}, {this->MONTHS.value(6),6},
|
||||
{this->MONTHS.value(7),7}, {this->MONTHS.value(8),8}, {this->MONTHS.value(9),9},
|
||||
{this->MONTHS.value(10),10}, {this->MONTHS.value(11),11}, {this->MONTHS.value(12),12} };
|
||||
|
||||
const int getMinuteGap( const int& minute, const int& gap=10 ),
|
||||
getMonthDays( const int& year, const int& month ),
|
||||
|
|
Loading…
Reference in New Issue