예제 #1
0
void MainWindow::setServerMode()
{
    auto model = dynamic_cast<LogModel*>(ui->tableView->sourceModel());
    if (model)
    {
        model->setServerMode(ui->actionServerMode->isChecked());
    }
    QSettings().setValue("serverMode", ui->actionServerMode->isChecked());
}
예제 #2
0
/** Save the ServerConfiguration in the TinyXml document
  *
  * The given ServerConfiguration pointer \b must be valid.
  *
  * \param sc The ServerConfiguration structure pointer
  *
  * \return \c true if the operation successed
  *
  */
bool RainbruRPG::Server::xmlServerConf::save(ServerConfiguration* sc){
  LOGI("Saving server configuration");

  setServerName(sc->getName());
  setDescription(sc->getDesc());
  setTechNote(sc->getTechNote());
  setServerMode(sc->getPlayMode(), sc->getEditMode(), sc->getFloodMode());
  setServerOption(sc->getIpAdress(), sc->getPort(), sc->getFtpPort(),
		  sc->getMaxClient(), sc->getType());

  // Database
  setDatabase(sc->getHostName(), sc->getDatabaseName(), 
	      sc->getUserName(), sc->getPassword() );

  bool success=doc->SaveFile(this->filename.c_str());
  if (!success){
    LOGW("An error occurs during server configuration saved");
  }
  else{
    LOGI("Server configuration correctly saved");
  }
}
예제 #3
0
MainWindow::MainWindow(const QString &fileName, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_taskbarButton(nullptr),
    m_monospaceFont(false)
{
    ui->setupUi(this);

    QSettings settings;

    m_monospaceFont = settings.value("monospaceFont", 0).toBool();
    if (m_monospaceFont)
    {
        const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
        ui->tableView->setFont(fixedFont);
    }

    AbstractLogModel *model;
    if (fileName.isEmpty())
    {
        auto logModel = new LogModel(this);
        model = logModel;
        if (settings.contains("autoSaveDirectory"))
        {
            logModel->setAutoSaveDirectory(settings.value("autoSaveDirectory").toString());
        }
        else
        {
            logModel->setAutoSaveDirectory(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
        }
        logModel->setMaxMessages(settings.value("maxMessages", 10000).toInt());
        logModel->setServerMode(settings.value("serverMode", false).toBool());
        setWindowTitle(windowTitle().arg(model->isListening() ? "Listening" : "Not listening"));

        connect(ui->actionDisconnectAll, &QAction::triggered, logModel, &LogModel::disconnectAll);
    }
    else
    {
        model = new LogMonitorFileModel(fileName, this);
        setWindowTitle(windowTitle().arg(QFileInfo(fileName).fileName()));
    }
    model->setBreakLines(settings.value("breakLines", 0).toBool());
    model->setColorBackground(LogColorBackground(settings.value("colorBackground", 0).toInt()));
    model->setTimestampPrecision(TimestampPrecision(settings.value("timestampPrecision", 0).toInt()));

    auto filtered = new LogFilter(this);
    filtered->setFilterCaseSensitivity(Qt::CaseInsensitive);
    filtered->setSourceModel(model);
    ui->tableView->setModel(filtered);

    connect(ui->errorFilter, &QToolButton::toggled, filtered, &LogFilter::showErrors);
    connect(ui->warningFilter, &QToolButton::toggled, filtered, &LogFilter::showWarnings);
    connect(ui->noticeFilter, &QToolButton::toggled, filtered, &LogFilter::showNotices);
    connect(ui->infoFilter, &QToolButton::toggled, filtered, &LogFilter::showInfos);

    ui->logMap->setModel(filtered);
    ui->logMap->setBuddyView(ui->tableView);

    auto src = ui->tableParent->layout();
    auto dest = new OverlayLayout(ui->tableParent);
    while (src->count())
    {
        dest->addItem(src->takeAt(0));
    }
    delete src;
    ui->tableParent->setLayout(dest);
    ui->searchBox->setVisible(false);

    ui->tableView->setVerticalHeader(new FixedHeader(Qt::Vertical, ui->tableView));
    ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
    ui->tableView->verticalHeader()->setDefaultSectionSize(23);
    ui->tableView->verticalHeader()->setHighlightSections(true);
    ui->tableView->verticalHeader()->setStretchLastSection(false);
    ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
    ui->tableView->horizontalHeader()->setStretchLastSection(false);
    ui->tableView->horizontalHeader()->setSectionResizeMode(6, QHeaderView::Stretch);
    ui->tableView->horizontalHeader()->setSectionsMovable(true);
    auto order = settings.value("columnOrder").toByteArray();
    for (int i = 0; i < order.size(); ++i)
    {
        ui->tableView->horizontalHeader()->moveSection(ui->tableView->horizontalHeader()->visualIndex(i), order[i]);
    }
    connect(ui->tableView->horizontalHeader(), &QHeaderView::sectionMoved, this, &MainWindow::columnMoved);

    connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::itemSelected);
    connect(ui->messageText, &QTextBrowser::anchorClicked, this, &MainWindow::anchorClicked);
    connect(ui->tableView, &QTableView::customContextMenuRequested, this, &MainWindow::itemMenu);

    ui->errorFilter->setChecked(settings.value("quickFilter/error", true).toBool());
    ui->warningFilter->setChecked(settings.value("quickFilter/warning", true).toBool());
    ui->noticeFilter->setChecked(settings.value("quickFilter/notice", true).toBool());
    ui->infoFilter->setChecked(settings.value("quickFilter/info", true).toBool());

    ui->errorFilter->setToolTip("error");
    ui->warningFilter->setToolTip("warning");
    ui->noticeFilter->setToolTip("notice");
    ui->infoFilter->setToolTip("info");

    if (settings.contains("customFilter"))
    {
        auto name = settings.value("customFilter").toString();
        auto& filters = Filter::getFilters();
        for (auto it = filters.begin(); it != filters.end(); ++it)
        {
            if (it->m_name == name)
            {
                static_cast<LogFilter*>(ui->tableView->model())->setCustomFilter(&(*it));
                ui->actionFilterNone->setChecked(false);
                ui->filterButton->setIcon(QIcon(":/default/filter"));
                ui->filterButton->setToolTip(name);
                break;
            }
        }
    }

    if (settings.contains("customHighlight"))
    {
        auto name = settings.value("customHighlight").toString();
        auto& highlights = HighlightSet::getSets();
        for (auto it = highlights.begin(); it != highlights.end(); ++it)
        {
            if (it->m_name == name)
            {
                static_cast<LogFilter*>(ui->tableView->model())->setHighlight(&(*it));
                ui->actionHighlightNone->setChecked(false);
                ui->highlightsButton->setIcon(QIcon(":/default/highlights"));
                ui->highlightsButton->setToolTip(name);
                break;
            }
        }
    }

    m_quickFilterEdited.setSingleShot(true);
    m_quickFilterEdited.setInterval(1000);
    connect(ui->textFilter, &QLineEdit::textChanged, this, &MainWindow::textFilterChanged);
    connect(ui->textFilter, &QLineEdit::editingFinished, this, &MainWindow::textFilterTimeout);
    connect(&m_quickFilterEdited, &QTimer::timeout, this, &MainWindow::textFilterTimeout);

    connect(ui->searchClose, &QToolButton::clicked, ui->searchBox, &QFrame::hide);
    connect(ui->searchDown, &QToolButton::clicked, this, &MainWindow::findNext);
    connect(ui->searchUp, &QToolButton::clicked, this, &MainWindow::findPrevious);
    ui->searchText->installEventFilter(this);

    ui->actionOpen->setShortcut(QKeySequence(QKeySequence::Open));
    ui->actionSaveAs->setShortcut(QKeySequence(QKeySequence::Save));
    ui->actionExit->setShortcut(QKeySequence(QKeySequence::Quit));
    ui->actionSelectAll->setShortcut(QKeySequence(QKeySequence::SelectAll));
    ui->actionFind->setShortcut(QKeySequence(QKeySequence::Find));
    ui->actionCopy->setShortcut(QKeySequence(QKeySequence::Copy));

    connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::openFile);
    connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::saveFile);
    connect(ui->actionExport, &QAction::triggered, this, &MainWindow::exportAsText);

    connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
    connect(ui->actionFind, &QAction::triggered, this, &MainWindow::openFind);
    connect(ui->actionCloseFind, &QAction::triggered, ui->searchBox, &QFrame::hide);
    connect(ui->actionSelectAll, &QAction::triggered, this, &MainWindow::selectAll);
    connect(ui->actionCopy, &QAction::triggered, this, &MainWindow::copySelection);
    connect(ui->actionCopyMessagesOnly, &QAction::triggered, this, &MainWindow::copyMessages);

    connect(ui->actionNextError, &QAction::triggered, ui->tableView, &LogView::nextError);
    connect(ui->actionPreviousError, &QAction::triggered, ui->tableView, &LogView::previousError);
    connect(ui->actionNextWarning, &QAction::triggered, ui->tableView, &LogView::nextWarning);
    connect(ui->actionPreviousWarning, &QAction::triggered, ui->tableView, &LogView::previousWarning);
    connect(ui->actionNextNotice, &QAction::triggered, ui->tableView, &LogView::nextNotice);
    connect(ui->actionPreviousNotice, &QAction::triggered, ui->tableView, &LogView::previousNotice);

    connect(ui->actionClear, &QAction::triggered, model, &AbstractLogModel::clear);

    ui->actionServerMode->setChecked(settings.value("serverMode").toBool());
    connect(ui->actionServerMode, &QAction::triggered, this, &MainWindow::setServerMode);
    connect(ui->actionSplitByPIDs, &QAction::triggered, this, &MainWindow::splitByPids);
    ui->actionSplitByPIDs->setChecked(settings.value("splitByPids").toBool());
    splitByPids();
    connect(ui->actionSettings, &QAction::triggered, this, &MainWindow::showSettings);
    connect(ui->actionAboutLogLite, &QAction::triggered, this, &MainWindow::showAboutDialog);

    connect(ui->actionScrollToBeginning, &QAction::triggered, ui->tableView, &LogView::scrollToBeginning);
    connect(ui->actionScrollToEnd, &QAction::triggered, ui->tableView, &LogView::scrollToEnd);


    QAction* columnActions[] = {
        ui->actionTime,
        ui->actionPID,
        ui->actionExecutable,
        ui->actionMachine,
        ui->actionModule,
        ui->actionChannel,
        ui->actionMessage,
    };
    for (int i = 0; i < int(sizeof(columnActions)/sizeof(columnActions[0])); ++i)
    {
        if (i + 1 < int(sizeof(columnActions)/sizeof(columnActions[0])))
        {
            auto key = QString(columnSettings[i]) + "Width";
            if (settings.contains(key))
            {
                ui->tableView->setColumnWidth(i, std::max(settings.value(key).toInt(), 32));
            }
        }
        columnActions[i]->setProperty("columnIndex", i);
        columnActions[i]->setProperty("setting", columnSettings[i]);
        connect(columnActions[i], &QAction::toggled, this, &MainWindow::columnMenuChanged);
        columnActions[i]->setChecked(settings.value(columnSettings[i], true).toBool());
        if (!columnActions[i]->isChecked())
        {
            ui->tableView->hideColumn(i);
        }
    }

    ui->tableView->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->tableView->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, &MainWindow::columnMenu);

    m_stats = new LogStatistics(this);
    m_stats->setModel(model);
    ui->statusBar->addPermanentWidget(m_stats);

    ui->splitter->setCollapsible(0, false);

    restoreGeometry(settings.value("geometry").toByteArray());
    restoreState(settings.value("windowState").toByteArray());
    ui->splitter->restoreState(settings.value("splitterSizes").toByteArray());

    if (fileName.isEmpty())
    {
        ui->tableView->selectionModel()->setCurrentIndex(ui->tableView->model()->index(0, 0), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
    }

#ifdef _WIN32
    auto timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, &MainWindow::updateTaskbarIcon);
    timer->start(1000);

    generateOverlayIcons(m_icons);
#endif

    connect(ui->actionEditFilters, &QAction::triggered, this, &MainWindow::editFilters);
    connect(ui->actionEditHighlights, &QAction::triggered, this, &MainWindow::editHighlights);

    connect(ui->menuFilters, &QMenu::aboutToShow, this, &MainWindow::buildFiltersMenu);
    connect(ui->menuFilters, &QMenu::triggered, this, &MainWindow::customFilterSet);

    connect(ui->menuHighlights, &QMenu::aboutToShow, this, &MainWindow::buildHighlightsMenu);
    connect(ui->menuHighlights, &QMenu::triggered, this, &MainWindow::highlightSet);

    connect(ui->filterButton, &QToolButton::clicked, this, &MainWindow::showFilterMenu);
    connect(ui->highlightsButton, &QToolButton::clicked, this, &MainWindow::showHighlightsMenu);

    connect(ui->menu_Disconnect_Client, &QMenu::aboutToShow, this, &MainWindow::buildClientsMenu);

    connect(ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);

    setAcceptDrops(true);
}