log file handling as standalone dialog finished
This commit is contained in:
@@ -18,15 +18,152 @@
|
||||
|
||||
#include "logfiledialog.h"
|
||||
#include "ui_logfiledialog.h"
|
||||
#include <QtCore>
|
||||
#include "guilog.h"
|
||||
#include "configfile.h"
|
||||
#include "mymessagebox.h"
|
||||
|
||||
LogFileDialog::LogFileDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
LogFileDialog::LogFileDialog(QWidget *parent, ConfigFile *c) :
|
||||
QDialog(parent), myConfig(c),
|
||||
ui(new Ui::LogFileDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect( ui->pushButton_deleteLog, SIGNAL(clicked()), this, SLOT (deleteLogFile()));
|
||||
connect( ui->pushButton_exportLogHtml, SIGNAL(clicked()), this, SLOT (exportLogToHtml()));
|
||||
connect( ui->pushButton_exportLogTxt, SIGNAL(clicked()), this, SLOT (exportLogToTxt()));
|
||||
connect( ui->pushButton_saveLogAs, SIGNAL(clicked()), this, SLOT (saveLogFileAs()));
|
||||
connect( ui->treeWidget_logFiles, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(showLogFilePreview()));
|
||||
}
|
||||
|
||||
LogFileDialog::~LogFileDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void LogFileDialog::exec()
|
||||
{
|
||||
refreshLogFileList();
|
||||
QDialog::exec();
|
||||
}
|
||||
|
||||
void LogFileDialog::refreshLogFileList()
|
||||
{
|
||||
QDir logFileDir;
|
||||
logFileDir.setPath(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str()));
|
||||
QStringList filters;
|
||||
filters << "*.pdb";
|
||||
QFileInfoList dbFilesList = logFileDir.entryInfoList(filters, QDir::Files, QDir::Time);
|
||||
|
||||
QFileInfo currentSqliteLogFile(QString::fromStdString(myGuiLog->getMySqliteLogFileName()));
|
||||
|
||||
ui->treeWidget_logFiles->clear();
|
||||
int i;
|
||||
for (i=0; i < dbFilesList.size(); i++) {
|
||||
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem;
|
||||
item->setText(0, dbFilesList.at(i).fileName());
|
||||
item->setData(0, Qt::UserRole, dbFilesList.at(i).absoluteFilePath());
|
||||
if(currentSqliteLogFile.fileName() == dbFilesList.at(i).fileName()) {
|
||||
item->setData(0, Qt::BackgroundColorRole, QColor(Qt::red));
|
||||
item->setData(0, Qt::TextColorRole, QColor(Qt::white));
|
||||
item->setData(0, Qt::UserRole+1, "current");
|
||||
}
|
||||
ui->treeWidget_logFiles->addTopLevelItem(item);
|
||||
}
|
||||
ui->treeWidget_logFiles->sortItems(0, Qt::DescendingOrder);
|
||||
}
|
||||
|
||||
void LogFileDialog::deleteLogFile()
|
||||
{
|
||||
QList<QTreeWidgetItem*> selectedItemsList = ui->treeWidget_logFiles->selectedItems();
|
||||
|
||||
if(!selectedItemsList.isEmpty() && !( selectedItemsList.size() == 1 && selectedItemsList.front()->data(0, Qt::UserRole+1).toString() == "current" )) {
|
||||
|
||||
int ret = MyMessageBox::warning(this, tr("PokerTH - Delete log files"),
|
||||
tr("Do you really want to delete the selected log files?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if(ret == QMessageBox::Yes) {
|
||||
for (int i = 0; i < selectedItemsList.size(); ++i) {
|
||||
if(selectedItemsList.at(i)->data(0, Qt::UserRole+1).toString() != "current") {
|
||||
|
||||
if(!QFile::remove(selectedItemsList.at(i)->data(0, Qt::UserRole).toString())) {
|
||||
MyMessageBox::warning(this, "Remove log file", "PokerTH cannot remove this log file, please verify that you have write access to this file!", QMessageBox::Close );
|
||||
}
|
||||
}
|
||||
}
|
||||
refreshLogFileList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogFileDialog::exportLogToHtml()
|
||||
{
|
||||
QTreeWidgetItem* selectedItem = ui->treeWidget_logFiles->currentItem();
|
||||
|
||||
if(selectedItem) {
|
||||
QFileInfo fi(selectedItem->text(0));
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export PokerTH log file to HTML"),
|
||||
QDir::homePath()+"/"+fi.baseName()+".html",
|
||||
tr("PokerTH HTML log (*.html)"));
|
||||
|
||||
if(!fileName.isEmpty()) {
|
||||
myGuiLog->exportLogPdbToHtml(selectedItem->data(0, Qt::UserRole).toString(),fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogFileDialog::exportLogToTxt()
|
||||
{
|
||||
QTreeWidgetItem* selectedItem = ui->treeWidget_logFiles->currentItem();
|
||||
|
||||
if(selectedItem) {
|
||||
QFileInfo fi(selectedItem->text(0));
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Export PokerTH log file to plain text"),
|
||||
QDir::homePath()+"/"+fi.baseName()+".txt",
|
||||
tr("PokerTH plain text log (*.txt)"));
|
||||
|
||||
if(!fileName.isEmpty()) {
|
||||
myGuiLog->exportLogPdbToTxt(selectedItem->data(0, Qt::UserRole).toString(),fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogFileDialog::saveLogFileAs()
|
||||
{
|
||||
QTreeWidgetItem* selectedItem = ui->treeWidget_logFiles->currentItem();
|
||||
|
||||
if(selectedItem) {
|
||||
QFileInfo fi(selectedItem->text(0));
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save PokerTH log file"),
|
||||
QDir::homePath()+"/"+fi.baseName()+".pdb",
|
||||
tr("PokerTH SQL log (*.pdb)"));
|
||||
|
||||
if(!fileName.isEmpty()) {
|
||||
QFile::copy(selectedItem->data(0, Qt::UserRole).toString(), fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LogFileDialog::showLogFilePreview()
|
||||
{
|
||||
QTreeWidgetItem* selectedItem = ui->treeWidget_logFiles->currentItem();
|
||||
|
||||
if(selectedItem) {
|
||||
myGuiLog->showLog(selectedItem->data(0, Qt::UserRole).toString(), ui->textBrowser_logPreview);
|
||||
}
|
||||
|
||||
QTextCursor cursor(ui->textBrowser_logPreview->textCursor());
|
||||
cursor.movePosition(QTextCursor::Start);
|
||||
ui->textBrowser_logPreview->setTextCursor(cursor);
|
||||
}
|
||||
|
||||
void LogFileDialog::keyPressEvent ( QKeyEvent * event )
|
||||
{
|
||||
if (event->key() == Qt::Key_Delete ) { /*Delete*/
|
||||
if(ui->treeWidget_logFiles->hasFocus()) {
|
||||
ui->pushButton_deleteLog->click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,19 +21,38 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class LogFileDialog;
|
||||
}
|
||||
|
||||
|
||||
class guiLog;
|
||||
class ConfigFile;
|
||||
|
||||
class LogFileDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LogFileDialog(QWidget *parent = 0);
|
||||
explicit LogFileDialog(QWidget *parent = 0, ConfigFile *c = 0);
|
||||
~LogFileDialog();
|
||||
|
||||
void setGuiLog(guiLog *g) { myGuiLog = g; }
|
||||
void exec();
|
||||
|
||||
public slots:
|
||||
void refreshLogFileList();
|
||||
void deleteLogFile();
|
||||
void exportLogToHtml();
|
||||
void exportLogToTxt();
|
||||
void saveLogFileAs();
|
||||
void showLogFilePreview();
|
||||
void keyPressEvent ( QKeyEvent * event );
|
||||
|
||||
private:
|
||||
ConfigFile *myConfig;
|
||||
guiLog *myGuiLog;
|
||||
Ui::LogFileDialog *ui;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user