Skip to content
Permalink
Browse files

refactoring.

  • Loading branch information...
haraki committed Jun 4, 2019
1 parent d22f128 commit fc91072210790717b15e5e9c16ab90bf5f3c4b83
Showing with 126 additions and 70 deletions.
  1. +106 −60 mainwindow.cpp
  2. +20 −10 mainwindow.h
@@ -31,9 +31,13 @@ MainWindow::MainWindow(QWidget *parent/* = Q_NULLPTR*/)
DoubleFolderPanel* doubleFolderPanel = new DoubleFolderPanel(ui->mainWidget);

connect(m_file,
SIGNAL(outputConsole(const QString)),
SIGNAL(outputConsole(const QString&)),
this,
SLOT(onOutputConsole(const QString)));
SLOT(onOutputConsole(const QString&)));
connect(this,
SIGNAL(outputConsole(const QString&)),
this,
SLOT(onOutputConsole(const QString&)));

connect(doubleFolderPanel,
SIGNAL(statusChanged(const QString&)),
@@ -175,91 +179,77 @@ void MainWindow::closeEvent(QCloseEvent* event)
QMainWindow::closeEvent(event);
}

void MainWindow::onOpenFile(ViewerType viewerType)
void MainWindow::emitOutputConsole(const QString& consoleString)
{
qDebug() << "MainWindow::onOpenFile()";

DoubleFolderPanel* doubleFolderPanel = ui->mainWidget->findChild<DoubleFolderPanel*>("DoubleFolderPanel");
if(doubleFolderPanel == Q_NULLPTR)
{
return;
}

FolderForm* activeFolderForm = doubleFolderPanel->getActiveFolderForm();
if(activeFolderForm == Q_NULLPTR)
{
return;
}

QString path = activeFolderForm->getCurrentFileInfo().absoluteFilePath();

onOpenFile(path, viewerType);
emit outputConsole(consoleString);
}

void MainWindow::onOpenFile(const QString& path, ViewerType viewerType/* = ViewerType::Auto*/)
int MainWindow::openFile(const QString& path, ViewerType viewerType/* = ViewerType::Auto*/)
{
DoubleFolderPanel* doubleFolderPanel = ui->mainWidget->findChild<DoubleFolderPanel*>("DoubleFolderPanel");
if(doubleFolderPanel == Q_NULLPTR)
{
return;
return -1;
}

if(QFileInfo(path).isDir())
{
// ディレクトリ移動
if(viewerType == ViewerType::Auto)
{
FolderForm* activeFolderForm = doubleFolderPanel->getActiveFolderForm();
if(activeFolderForm == Q_NULLPTR)
{
return;
return -1;
}

int ret = activeFolderForm->setPath(path);
if(ret < 0)
{
onOutputConsole(tr("Folder can not be opened.\n"));
emitOutputConsole(tr("Folder can not be opened : %1\n").arg(path));
}
}
else
{
onOutputConsole(tr("Folder can not be opened with the viewer.\n"));
emitOutputConsole(tr("Folder can not be opened with the viewer : %1\n").arg(path));
}

return;
}

ViewerBase* viewer = m_viewerDispatcher->dispatcher(path, viewerType);
if(viewer == Q_NULLPTR)
else
{
return;
}
// ファイルを Viewer でオープン
ViewerBase* viewer = m_viewerDispatcher->dispatcher(path, viewerType);
if(viewer == Q_NULLPTR)
{
return -1;
}

connect(viewer,
SIGNAL(closeViewer(const QString)),
this,
SLOT(onCloseViewer(const QString)));
connect(viewer,
SIGNAL(closeViewer(const QString)),
this,
SLOT(onCloseViewer(const QString)));

// 余計な操作ができないよう、ビュアー時はメニューは無効化
ui->menuBar->setEnabled(false);
// 余計な操作ができないよう、ビュアー時はメニューは無効化
ui->menuBar->setEnabled(false);

ui->mainWidget->layout()->addWidget(viewer);
ui->mainWidget->installEventFilter(viewer);
ui->mainWidget->layout()->addWidget(viewer);
ui->mainWidget->installEventFilter(viewer);

doubleFolderPanel->setVisible(false);
doubleFolderPanel->setVisible(false);

viewer->start(this);
viewer->start(this);
}

return 0;
}

void MainWindow::onCloseViewer(const QString& viewerObjectName)
int MainWindow::closeViewer(const QString& viewerObjectName)
{
qDebug() << "MainWindow::onCloseViewer()";

ui->menuBar->setEnabled(true);

QWidget* viewer = ui->mainWidget->findChild<QWidget*>(viewerObjectName);
if(viewer == Q_NULLPTR)
{
return;
return -1;
}

viewer->setVisible(false);
@@ -269,30 +259,32 @@ void MainWindow::onCloseViewer(const QString& viewerObjectName)
DoubleFolderPanel* doubleFolderPanel = ui->mainWidget->findChild<DoubleFolderPanel*>("DoubleFolderPanel");
if(doubleFolderPanel == Q_NULLPTR)
{
return;
return -1;
}

if(!doubleFolderPanel->isVisible())
{
doubleFolderPanel->setVisible(true);
}

return 0;
}

void MainWindow::onOpenWithApp(const QString& path)
int MainWindow::openWithApp(const QString& path)
{
qDebug() << "MainWindow::onOpenWithApp()";

if(!QDesktopServices::openUrl(QUrl("file:///" + path)))
{
qDebug() << "open url error:" << path;
onOutputConsole(tr("Open failed : ") + path);
emitOutputConsole(tr("Open failed : %1\n").arg(path));

return -1;
}

return 0;
}

void MainWindow::onOpenWithTextEditor(const QString& dirPath, const QStringList& filePaths)
int MainWindow::openWithTextEditor(const QString& dirPath, const QStringList& filePaths)
{
qDebug() << "MainWindow::onOpenWithTextEditor()";

QString appPath = Settings::getInstance()->getTextEditorPath();
QString args = Settings::getInstance()->getTextEditorArgs();

@@ -306,7 +298,7 @@ void MainWindow::onOpenWithTextEditor(const QString& dirPath, const QStringList&
launchPreferencesDialog(PreferencesDialogTabPage::ExternalApp);
}

return;
return 0;
}

#ifdef Q_OS_MAC
@@ -321,14 +313,61 @@ void MainWindow::onOpenWithTextEditor(const QString& dirPath, const QStringList&

qDebug() << "dirPath : " << dirPath << ", filePaths : " << filePaths << ", command : " << command;

launchExternalApp(command, dirPath);
if(!launchExternalApp(command, dirPath))
{
return -1;
}

return 0;
}

void MainWindow::onStatusChanged(const QString& statusString)
void MainWindow::onOpenFile(ViewerType viewerType)
{
qDebug() << "MainWindow::onStatusChanged : " << statusString;
qDebug() << "MainWindow::onOpenFile()";

statusBar()->showMessage(statusString);
DoubleFolderPanel* doubleFolderPanel = ui->mainWidget->findChild<DoubleFolderPanel*>("DoubleFolderPanel");
if(doubleFolderPanel == Q_NULLPTR)
{
return;
}

FolderForm* activeFolderForm = doubleFolderPanel->getActiveFolderForm();
if(activeFolderForm == Q_NULLPTR)
{
return;
}

QString path = activeFolderForm->getCurrentFileInfo().absoluteFilePath();

openFile(path, viewerType);
}

void MainWindow::onOpenFile(const QString& path, ViewerType viewerType/* = ViewerType::Auto*/)
{
qDebug() << "MainWindow::onOpenFile()";

openFile(path, viewerType);
}

void MainWindow::onCloseViewer(const QString& viewerObjectName)
{
qDebug() << "MainWindow::onCloseViewer()";

closeViewer(viewerObjectName);
}

void MainWindow::onOpenWithApp(const QString& path)
{
qDebug() << "MainWindow::onOpenWithApp()";

openWithApp(path);
}

void MainWindow::onOpenWithTextEditor(const QString& dirPath, const QStringList& filePaths)
{
qDebug() << "MainWindow::onOpenWithTextEditor()";

openWithTextEditor(dirPath, filePaths);
}

void MainWindow::onCreateNewFileFinished(const QString& filePath)
@@ -338,7 +377,14 @@ void MainWindow::onCreateNewFileFinished(const QString& filePath)
QStringList filePaths;
filePaths.push_back(filePath);

onOpenWithTextEditor(QFileInfo(filePath).absolutePath(), filePaths);
openWithTextEditor(QFileInfo(filePath).absolutePath(), filePaths);
}

void MainWindow::onStatusChanged(const QString& statusString)
{
qDebug() << "MainWindow::onStatusChanged : " << statusString;

statusBar()->showMessage(statusString);
}

void MainWindow::onOutputConsole(const QString& consoleString)
@@ -27,16 +27,6 @@ class MainWindow : public QMainWindow
explicit MainWindow(QWidget *parent = Q_NULLPTR);
~MainWindow() Q_DECL_OVERRIDE;

public Q_SLOTS:
void onOpenFile(ViewerType viewerType);
void onOpenFile(const QString& path, ViewerType viewerType = ViewerType::Auto);
void onCloseViewer(const QString& viewerName);
void onOpenWithApp(const QString& path);
void onOpenWithTextEditor(const QString& dirPath, const QStringList& filePaths);
void onStatusChanged(const QString& statusString);
void onCreateNewFileFinished(const QString& filePath);
void onOutputConsole(const QString& consoleString);

private:
void closeEvent(QCloseEvent* event) Q_DECL_OVERRIDE;

@@ -52,7 +42,27 @@ public Q_SLOTS:

void about();

Q_SIGNALS:
void outputConsole(const QString& consoleString);

private:
int openFile(const QString& path, ViewerType viewerType = ViewerType::Auto);
int closeViewer(const QString& viewerObjectName);
int openWithApp(const QString& path);
int openWithTextEditor(const QString& dirPath, const QStringList& filePaths);

void emitOutputConsole(const QString& consoleString);

private Q_SLOTS:
void onOpenFile(ViewerType viewerType);
void onOpenFile(const QString& path, ViewerType viewerType = ViewerType::Auto);
void onCloseViewer(const QString& viewerName);
void onOpenWithApp(const QString& path);
void onOpenWithTextEditor(const QString& dirPath, const QStringList& filePaths);
void onCreateNewFileFinished(const QString& filePath);
void onStatusChanged(const QString& statusString);
void onOutputConsole(const QString& consoleString);

void on_actionOpen_triggered();
void on_actionOpenWithTextViewer_triggered();
void on_actionOpenWithHexViewer_triggered();

0 comments on commit fc91072

Please sign in to comment.
You can’t perform that action at this time.