Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Исправление issue #30 #31

Merged
merged 5 commits into from
May 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions avalon.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
TARGET = avalon
DEPENDPATH += . model storage
INCLUDEPATH += . model storage

macx {
QMAKE_CXX = clang
}

# Input
HEADERS += colorer.h \
form_date.h \
Expand Down Expand Up @@ -68,7 +71,8 @@
storage/query.h \
storage/sqlite_database.h \
storage/sqlite_storage.h \
storage/storage_factory.h
storage/storage_factory.h \
logger.h
SOURCES += form_date.cpp \
form_date_ui.cpp \
form_input.cpp \
Expand Down Expand Up @@ -107,5 +111,6 @@
storage/query.cpp \
storage/sqlite_database.cpp \
storage/sqlite_storage.cpp \
storage/storage_factory.cpp
storage/storage_factory.cpp \
logger.cpp
RESOURCES += resource.qrc
5 changes: 4 additions & 1 deletion dev/create_macosx_bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ PATH_TO_DEV=../avalon.app/Contents/dev
mkdir $PATH_TO_DEV
cp -f avalon.sqlite.sql $PATH_TO_DEV

macdeployqt ../avalon.app -dmg
if [ -z "$DEBUG" ]; then
macdeployqt ../avalon.app -dmg
fi

33 changes: 31 additions & 2 deletions form_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "form_settings.h"
//----------------------------------------------------------------------------------------------
#include "colorer.h"
#include "global.h"
//----------------------------------------------------------------------------------------------

FormSettings::FormSettings (QWidget* parent) : FormSettingsUI (parent), m_sqlite3Exists(false)
Expand All @@ -23,6 +24,9 @@ FormSettings::FormSettings (QWidget* parent) : FormSettingsUI (parent), m_sqlite
connect(m_button_cancel_ui, SIGNAL(clicked()), this, SLOT(reject()));
connect(m_button_ok_ui, SIGNAL(clicked()), this, SLOT(button_ok_clicked()));

connect(m_button_cancel_other, SIGNAL(clicked()), this, SLOT(reject()));
connect(m_button_ok_other, SIGNAL(clicked()), this, SLOT(button_ok_clicked()));

connect(m_check_use_proxy, SIGNAL(stateChanged(int)), this, SLOT(check_use_proxy_state_changed(int)));

connect(m_combo_database_type, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(combo_database_type_current_index_changed(const QString&)));
Expand All @@ -32,7 +36,11 @@ FormSettings::FormSettings (QWidget* parent) : FormSettingsUI (parent), m_sqlite
connect(m_button_database_create, SIGNAL(clicked()), this, SLOT(button_database_create_clicked()));

connect(m_text_database_file, SIGNAL(textChanged(const QString&)), this, SLOT(text_changed_slot(const QString&)));
restore();

connect(m_combo_logging_level, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(combo_logging_level_current_index_changed(const QString&)));


restore();
}
//----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -71,12 +79,22 @@ void FormSettings::button_database_create_clicked ()
QProcess p;
QString pathToSql = QDir::currentPath();
#ifdef __APPLE__
pathToSql.append("/..");
pathToSql.append("/avalon.app/Contents");
#endif
pathToSql.append("/dev/avalon.sqlite.sql");
QFileInfo sqlFileInfo(pathToSql);
if(!sqlFileInfo.isFile())
{
qWarning() << "Can not find script for creating database,"
<< pathToSql;
return;
}
QString cmd = "sqlite3 -init " + pathToSql + " " + pathToDb + " .quit";
qDebug() << "Creating database with command" << cmd;
p.start(cmd);
p.waitForFinished(-1);
qDebug() << "sqlite3 exit code" << p.exitCode() << "stdout" << p.readAllStandardOutput()
<< "stderr" << p.readAllStandardError();

m_button_database_create->setEnabled(can_create_sqlitedb(m_text_database_file->text()));
}
Expand Down Expand Up @@ -177,6 +195,10 @@ void FormSettings::save ()
#ifdef AVALON_USE_ASPELL
settings.setValue("ui/spellchecker", (m_check_spellchecker->checkState() == Qt::Checked ? 1 : 0));
#endif

QtMsgType logLevel = (QtMsgType)m_combo_logging_level->currentIndex();
settings.setValue("other/logging_level", logLevel);
g_logger.setDebugLevel(logLevel);
}
//----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -293,6 +315,13 @@ void FormSettings::restore ()
m_check_spellchecker->setCheckState(Qt::Unchecked);
#endif

int loggingLevel = settings.value("other/logging_level", 1).toInt();
m_combo_logging_level->setCurrentIndex(loggingLevel);

m_text_rsdn_host->setFocus();
}
//----------------------------------------------------------------------------------------------

void FormSettings::combo_logging_level_current_index_changed(const QString& text)
{
}
1 change: 1 addition & 0 deletions form_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class FormSettings : public FormSettingsUI
* \brief Смена типа БД
*/
void combo_database_type_current_index_changed (const QString& text);
void combo_logging_level_current_index_changed(const QString& text);
};

#endif // _avalon_form_settings_h_
62 changes: 62 additions & 0 deletions form_settings_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ FormSettingsUI::FormSettingsUI (QWidget* parent) : QDialog (parent, Qt::WindowTi
m_ui_settings = new QWidget();
m_tab->addTab(m_ui_settings, QString::fromUtf8("интерфейс"));

m_other_settings = new QWidget();
m_tab->addTab(m_other_settings, QString::fromUtf8("прочее"));

//
// таб настроек сети
//
Expand Down Expand Up @@ -415,7 +418,66 @@ FormSettingsUI::FormSettingsUI (QWidget* parent) : QDialog (parent, Qt::WindowTi

m_spacer_button_ui = new QSpacerItem(1, 1, QSizePolicy::Maximum, QSizePolicy::Expanding);
m_layout_button_ui->addItem(m_spacer_button_ui);

//
// таб прочих настроек
//

m_layout_other_spacer = new QVBoxLayout(m_other_settings);

m_layout_other = new QHBoxLayout();
m_layout_other_spacer->addLayout(m_layout_other);

m_other_spacer = new QSpacerItem(1, height(), QSizePolicy::Maximum, QSizePolicy::Expanding);
m_layout_other_spacer->addItem(m_other_spacer);

//
// подписи к полям (остальное)
//

m_layout_label_other = new QVBoxLayout();
m_layout_other->addLayout(m_layout_label_other);

m_label_logging_level = new QLabel(this);
m_label_logging_level->setText(QString::fromUtf8("Уровень логирования:"));
m_layout_label_other->addWidget(m_label_logging_level);

//
// поля (хранилище)
//

m_layout_text_other = new QVBoxLayout();
m_layout_other->addLayout(m_layout_text_other);

m_combo_logging_level = new QComboBox(this);
m_combo_logging_level->insertItem(0, "Error");
m_combo_logging_level->insertItem(0, "Warning");
m_combo_logging_level->insertItem(0, "Debug");
m_combo_logging_level->setCurrentIndex(2);
m_layout_text_other->addWidget(m_combo_logging_level);

//
// кнопки (хранилище)
//

m_layout_button_other = new QVBoxLayout();
m_layout_other->addLayout(m_layout_button_other);

m_button_ok_other = new QPushButton(this);
m_button_ok_other->setText(QString::fromUtf8("OK"));
m_button_ok_other->setShortcut(QKeySequence("Return"));
m_button_ok_other->setDefault(true);
m_layout_button_other->addWidget(m_button_ok_other);

m_button_cancel_other = new QPushButton(this);
m_button_cancel_other->setText(QString::fromUtf8("Отмена"));
m_button_cancel_other->setShortcut(QKeySequence("Esc"));
m_layout_button_other->addWidget(m_button_cancel_other);

m_spacer_button_other = new QSpacerItem(1, 1, QSizePolicy::Maximum, QSizePolicy::Expanding);
m_layout_button_other->addItem(m_spacer_button_other);
}

//----------------------------------------------------------------------------------------------

FormSettingsUI::~FormSettingsUI ()
Expand Down
15 changes: 15 additions & 0 deletions form_settings_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ class FormSettingsUI : public QDialog
QSpacerItem* m_spacer_button_ui; /*!< \brief Выравнивание кнопок вверх */
QSpacerItem* m_ui_spacer; /*!< \brief Выравнивание всего вверх */



QWidget* m_other_settings; /*!< \brief Виджет таба для дополнительных настроек */
QVBoxLayout* m_layout_other_spacer; /*!< \brief Layout для выравнивания по вертикали */
QHBoxLayout* m_layout_other; /*!< \brief Общий layout для настроек хранилища */
QVBoxLayout* m_layout_label_other; /*!< \brief Layout для надписей */
QLabel* m_label_logging_level; /*!< \brief Уровень логирования */
QVBoxLayout* m_layout_text_other; /*!< \brief Layout для текстовых полей */
QComboBox* m_combo_logging_level; /*!< \brief Тип базы хранилища */
QVBoxLayout* m_layout_button_other; /*!< \brief Layout для кнопок */
QPushButton* m_button_ok_other; /*!< \brief OK */
QPushButton* m_button_cancel_other; /*!< \brief Отмена */
QSpacerItem* m_spacer_button_other; /*!< \brief Выравнивание кнопок вверх */
QSpacerItem* m_other_spacer; /*!< \brief Выравнивание всего вверх */

private:

QIntValidator* m_timer_validator; /*!< \brief Валидатор значения в поле "время пометки как прочитанное" */
Expand Down
3 changes: 3 additions & 0 deletions global.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#include "colorer.h"
#include "model/user.h"
#include "logger.h"

extern Logger g_logger;

/*!
* \brief Глобальные настройки
Expand Down
49 changes: 49 additions & 0 deletions logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "logger.h"
#include <QDebug>

Logger::Logger() : m_debugLevel(QtCriticalMsg)
{
#ifndef __APPLE__
m_logfileName = QDir::tempPath();
#else
m_logfileName = QDir::homePath () + "/Library/Logs/Avalon";
QDir logDir(m_logfileName);
qDebug() << logDir.absolutePath();
logDir.mkpath(logDir.absolutePath());
#endif
m_logfileName += "/avalon_" +
QDateTime::currentDateTime().toString(Qt::ISODate) + ".log";
}

void Logger::setDebugLevel(QtMsgType level)
{
m_debugLevel = level;
}

void Logger::logMessage(QtMsgType type, const char *msg)
{
if(type < m_debugLevel)
return;

QString txt;
switch (type) {
case QtDebugMsg:
txt = QString("%1 : debug: %2").arg(QTime::currentTime().toString(Qt::ISODate), msg);
break;

case QtWarningMsg:
txt = QString("%1 : warning: %2").arg(QTime::currentTime().toString(Qt::ISODate), msg);
break;
case QtCriticalMsg:
txt = QString("%1 : critical: %2").arg(QTime::currentTime().toString(Qt::ISODate), msg);
break;
case QtFatalMsg:
txt = QString("%1 : fatal: %2").arg(QTime::currentTime().toString(Qt::ISODate), msg);
abort();
}

QFile outFile(m_logfileName);
bool res = outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
}
17 changes: 17 additions & 0 deletions logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef LOGGER_H
#define LOGGER_H

#include "sysheaders.h"

class Logger
{
public:
Logger();
void setDebugLevel(QtMsgType level);
void logMessage(QtMsgType type, const char *msg);
private:
QString m_logfileName;
QtMsgType m_debugLevel;
};

#endif // LOGGER_H
22 changes: 21 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@

#include "form_main.h"
#include "global.h"
#include "logger.h"
#include <memory>

Logger g_logger;

static void log_helper(QtMsgType type, const char *msg)
{
g_logger.logMessage(type, msg);
}

void init_logging()
{
QSettings settings;
int loggingLevel = settings.value("other/logging_level", 2).toInt();
g_logger.setDebugLevel((QtMsgType)loggingLevel);
}

/*!
* (no comments)
Expand All @@ -24,6 +40,8 @@ int main (int argc, char* argv[])

QApplication app(argc, argv);

qInstallMsgHandler(log_helper);

#ifndef Q_WS_MAC
// отображать иконки в меню для всех, кроме MacOS
app.setAttribute(Qt::AA_DontShowIconsInMenus, false);
Expand Down Expand Up @@ -57,5 +75,7 @@ int main (int argc, char* argv[])

app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));

return app.exec();
init_logging();

return app.exec();
}