Skip to content

Commit

Permalink
'Panel' is enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletGiraffe committed Sep 7, 2024
1 parent d21ce67 commit 8f77c3e
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 58 deletions.
40 changes: 20 additions & 20 deletions file-commander-core/src/ccontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ CController* CController::_instance = nullptr;

CController::CController() :
_favoriteLocations{KEY_FAVORITES},
_leftPanel{LeftPanel},
_rightPanel{RightPanel},
_leftPanel{Panel::LeftPanel},
_rightPanel{Panel::RightPanel},
_pluginProxy{[this](const std::function<void()>& code) {execOnUiThread(code);}},
_workerThreadPool{2, "CController thread pool"}
{
Expand Down Expand Up @@ -138,7 +138,7 @@ std::pair<bool /*success*/, QString/*volume root path*/> CController::switchToVo
else
{
// Otherwise navigate to the last known path for this volume, or its root if no path was recorded previously
const QString lastPathForDrive = CSettings{}.value(p == LeftPanel ? QString{KEY_LAST_PATH_FOR_DRIVE_L}.arg(drivePath.toHtmlEscaped()) : QString{KEY_LAST_PATH_FOR_DRIVE_R}.arg(drivePath.toHtmlEscaped()), drivePath).toString();
const QString lastPathForDrive = CSettings{}.value(p == Panel::LeftPanel ? QString{KEY_LAST_PATH_FOR_DRIVE_L}.arg(drivePath.toHtmlEscaped()) : QString{KEY_LAST_PATH_FOR_DRIVE_R}.arg(drivePath.toHtmlEscaped()), drivePath).toString();
return {setPath(p, toPosixSeparators(lastPathForDrive), refreshCauseOther) == FileOperationResultCode::Ok, drivePath};
}
}
Expand Down Expand Up @@ -351,9 +351,9 @@ const CPanel &CController::panel(Panel p) const
{
switch (p)
{
case LeftPanel:
case Panel::LeftPanel:
return _leftPanel;
case RightPanel:
case Panel::RightPanel:
return _rightPanel;
default:
assert_unconditional_r("Unknown panel");
Expand All @@ -365,9 +365,9 @@ CPanel& CController::panel(Panel p)
{
switch (p)
{
case LeftPanel:
case Panel::LeftPanel:
return _leftPanel;
case RightPanel:
case Panel::RightPanel:
return _rightPanel;
default:
assert_unconditional_r("Unknown panel");
Expand All @@ -379,9 +379,9 @@ const CPanel &CController::otherPanel(Panel p) const
{
switch (p)
{
case LeftPanel:
case Panel::LeftPanel:
return _rightPanel;
case RightPanel:
case Panel::RightPanel:
return _leftPanel;
default:
assert_unconditional_r("Uknown panel");
Expand All @@ -393,9 +393,9 @@ CPanel& CController::otherPanel(Panel p)
{
switch (p)
{
case LeftPanel:
case Panel::LeftPanel:
return _rightPanel;
case RightPanel:
case Panel::RightPanel:
return _leftPanel;
default:
assert_unconditional_r("Uknown panel");
Expand All @@ -408,20 +408,20 @@ Panel CController::otherPanelPosition(Panel p)
{
switch (p)
{
case LeftPanel:
return RightPanel;
case RightPanel:
return LeftPanel;
case Panel::LeftPanel:
return Panel::RightPanel;
case Panel::RightPanel:
return Panel::LeftPanel;
default:
assert_unconditional_r("Uknown panel");
return LeftPanel;
return Panel::LeftPanel;
}
}


Panel CController::activePanelPosition() const
{
assert_r(_activePanel == RightPanel || _activePanel == LeftPanel);
assert_r(_activePanel == Panel::RightPanel || _activePanel == Panel::LeftPanel);
return _activePanel;
}

Expand Down Expand Up @@ -516,8 +516,8 @@ void CController::volumesChanged(bool drivesListOrReadinessChanged) noexcept

for (auto& listener: _volumesChangedListeners)
{
listener->volumesChanged(drives, RightPanel, drivesListOrReadinessChanged);
listener->volumesChanged(drives, LeftPanel, drivesListOrReadinessChanged);
listener->volumesChanged(drives, Panel::RightPanel, drivesListOrReadinessChanged);
listener->volumesChanged(drives, Panel::LeftPanel, drivesListOrReadinessChanged);
}
}

Expand All @@ -537,5 +537,5 @@ void CController::saveDirectoryForCurrentVolume(Panel p)
assert_and_return_r(currentVolume, );

const QString drivePath = currentVolume->rootObjectInfo.fullAbsolutePath();
CSettings().setValue(p == LeftPanel ? QString{KEY_LAST_PATH_FOR_DRIVE_L}.arg(drivePath.toHtmlEscaped()) : QString{KEY_LAST_PATH_FOR_DRIVE_R}.arg(drivePath.toHtmlEscaped()), path.fullAbsolutePath());
CSettings().setValue(p == Panel::LeftPanel ? QString{KEY_LAST_PATH_FOR_DRIVE_L}.arg(drivePath.toHtmlEscaped()) : QString{KEY_LAST_PATH_FOR_DRIVE_R}.arg(drivePath.toHtmlEscaped()), path.fullAbsolutePath());
}
2 changes: 1 addition & 1 deletion file-commander-core/src/ccontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class CController final : public CVolumeEnumerator::IVolumeListObserver
#endif
CVolumeEnumerator _volumeEnumerator;
std::vector<IVolumeListObserver*> _volumesChangedListeners;
Panel _activePanel = UnknownPanel;
Panel _activePanel = Panel::UnknownPanel;

CWorkerThreadPool _workerThreadPool; // The thread used to execute tasks out of the UI thread
CExecutionQueue _uiQueue; // The queue for actions that must be executed on the UI thread
Expand Down
10 changes: 5 additions & 5 deletions file-commander-core/src/cpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CPanel::CPanel(Panel position) :
_panelPosition(position),
_workerThreadPool(
std::min(4u, std::thread::hardware_concurrency()),
std::string(position == LeftPanel ? "Left panel" : "Right panel") + " file list refresh thread pool"
std::string(position == Panel::LeftPanel ? "Left panel" : "Right panel") + " file list refresh thread pool"
)
{
}
Expand All @@ -43,9 +43,9 @@ CPanel::~CPanel()
void CPanel::restoreFromSettings()
{
CSettings s;
const QStringList historyList = s.value(_panelPosition == RightPanel ? KEY_HISTORY_R : KEY_HISTORY_L).toStringList();
const QStringList historyList = s.value(_panelPosition == Panel::RightPanel ? KEY_HISTORY_R : KEY_HISTORY_L).toStringList();
_history.addLatest(to_vector<QString>(historyList));
setPath(s.value(_panelPosition == LeftPanel ? KEY_LPANEL_PATH : KEY_RPANEL_PATH, QDir::homePath()).toString(), refreshCauseOther);
setPath(s.value(_panelPosition == Panel::LeftPanel ? KEY_LPANEL_PATH : KEY_RPANEL_PATH, QDir::homePath()).toString(), refreshCauseOther);
}

FileOperationResultCode CPanel::setPath(const QString &path, FileListRefreshCause operation)
Expand Down Expand Up @@ -108,10 +108,10 @@ FileOperationResultCode CPanel::setPath(const QString &path, FileListRefreshCaus
if (_history.currentItem() != newPath)
{
_history.addLatest(newPath);
settings.setValue(_panelPosition == RightPanel ? KEY_HISTORY_R : KEY_HISTORY_L, QVariant(QStringList(_history.list().cbegin(), _history.list().cend())));
settings.setValue(_panelPosition == Panel::RightPanel ? KEY_HISTORY_R : KEY_HISTORY_L, QVariant(QStringList(_history.list().cbegin(), _history.list().cend())));
}

settings.setValue(_panelPosition == LeftPanel ? KEY_LPANEL_PATH : KEY_RPANEL_PATH, newPath);
settings.setValue(_panelPosition == Panel::LeftPanel ? KEY_LPANEL_PATH : KEY_RPANEL_PATH, newPath);

if (_watcher.setPathToWatch(newPath) == false)
qInfo() << __FUNCTION__ << "Error setting path" << newPath << "to CFileSystemWatcher";
Expand Down
2 changes: 1 addition & 1 deletion file-commander-core/src/cpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using FileSystemWatcher = CFileSystemWatcherTimerBased;
#include <vector>
#include <utility>

enum Panel
enum class Panel
{
LeftPanel,
RightPanel,
Expand Down
4 changes: 2 additions & 2 deletions file-commander-core/src/pluginengine/cpluginengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ CFileCommanderViewerPlugin::PluginWindowPointerType CPluginEngine::createViewerW

PanelPosition CPluginEngine::pluginPanelEnumFromCorePanelEnum(Panel p)
{
assert_r(p != UnknownPanel);
return p == LeftPanel ? PluginLeftPanel : PluginRightPanel;
assert_r(p != Panel::UnknownPanel);
return p == Panel::LeftPanel ? PluginLeftPanel : PluginRightPanel;
}

CFileCommanderViewerPlugin *CPluginEngine::viewerForCurrentFile()
Expand Down
40 changes: 20 additions & 20 deletions qt-app/src/cmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ void CMainWindow::updateInterface()
if ((windowState() & Qt::WindowFullScreen) != 0)
ui->actionFull_screen_mode->setChecked(true);

const Panel lastActivePanel = (Panel)s.value(KEY_LAST_ACTIVE_PANEL, LeftPanel).toInt();
if (lastActivePanel == LeftPanel)
const Panel lastActivePanel = (Panel)s.value(KEY_LAST_ACTIVE_PANEL, (int)Panel::LeftPanel).toInt();
if (lastActivePanel == Panel::LeftPanel)
ui->leftPanel->setFocusToFileList();
else
ui->rightPanel->setFocusToFileList();
Expand Down Expand Up @@ -337,12 +337,12 @@ void CMainWindow::itemActivated(qulonglong hash, CPanelWidget *panel)

void CMainWindow::currentPanelChanged(const Panel panel)
{
if (panel == RightPanel)
if (panel == Panel::RightPanel)
{
_currentFileList = _rightPanelDisplayController.panelWidget();
_otherFileList = _leftPanelDisplayController.panelWidget();
}
else if (panel == LeftPanel)
else if (panel == Panel::LeftPanel)
{
_currentFileList = _leftPanelDisplayController.panelWidget();
_otherFileList = _rightPanelDisplayController.panelWidget();
Expand All @@ -357,7 +357,7 @@ void CMainWindow::currentPanelChanged(const Panel panel)
}

_controller->activePanelChanged(_currentFileList->panelPosition());
CSettings().setValue(KEY_LAST_ACTIVE_PANEL, _currentFileList->panelPosition());
CSettings().setValue(KEY_LAST_ACTIVE_PANEL, (int)_currentFileList->panelPosition());
ui->fullPath->setText(_controller->panel(_currentFileList->panelPosition()).currentDirPathNative());
CPluginEngine::get().currentPanelChanged(_currentFileList->panelPosition());
_commandLineCompleter.setModel(_currentFileList->sortModel());
Expand All @@ -372,11 +372,11 @@ void CMainWindow::uiThreadTimerTick()
// Window title management (#143)
void CMainWindow::updateWindowTitleWithCurrentFolderNames()
{
QString leftPanelDirName = _controller->panel(LeftPanel).currentDirName();
QString leftPanelDirName = _controller->panel(Panel::LeftPanel).currentDirName();
if (leftPanelDirName.length() > 1 && leftPanelDirName.endsWith('/'))
leftPanelDirName.chop(1);

QString rightPanelDirName = _controller->panel(RightPanel).currentDirName();
QString rightPanelDirName = _controller->panel(Panel::RightPanel).currentDirName();
if (rightPanelDirName.length() > 1 && rightPanelDirName.endsWith('/'))
rightPanelDirName.chop(1);

Expand Down Expand Up @@ -715,8 +715,8 @@ void CMainWindow::findFiles()
void CMainWindow::showHiddenFiles()
{
CSettings().setValue(KEY_INTERFACE_SHOW_HIDDEN_FILES, ui->action_Show_hidden_files->isChecked());
_controller->refreshPanelContents(LeftPanel);
_controller->refreshPanelContents(RightPanel);
_controller->refreshPanelContents(Panel::LeftPanel);
_controller->refreshPanelContents(Panel::RightPanel);
}

void CMainWindow::showAllFilesFromCurrentFolderAndBelow()
Expand Down Expand Up @@ -791,11 +791,11 @@ void CMainWindow::focusChanged(QWidget * /*old*/, QWidget * now)

for (int i = 0; i < ui->leftWidget->count(); ++i)
if (now == ui->leftWidget || WidgetUtils::widgetBelongsToHierarchy(now, ui->leftWidget->widget(i)))
currentPanelChanged(LeftPanel);
currentPanelChanged(Panel::LeftPanel);

for (int i = 0; i < ui->rightWidget->count(); ++i)
if (now == ui->rightWidget || WidgetUtils::widgetBelongsToHierarchy(now, ui->rightWidget->widget(i)))
currentPanelChanged(RightPanel);
currentPanelChanged(Panel::RightPanel);
}

void CMainWindow::panelContentsChanged(Panel p, FileListRefreshCause /*operation*/)
Expand All @@ -812,7 +812,7 @@ void CMainWindow::initCore()
ui->leftPanel->init(_controller.get());
ui->rightPanel->init(_controller.get());

_controller->activePanelChanged((Panel)CSettings().value(KEY_LAST_ACTIVE_PANEL, LeftPanel).toInt());
_controller->activePanelChanged((Panel)CSettings().value(KEY_LAST_ACTIVE_PANEL, (int)Panel::LeftPanel).toInt());

connect(qApp, &QApplication::focusChanged, this, &CMainWindow::focusChanged);

Expand Down Expand Up @@ -840,16 +840,16 @@ void CMainWindow::initCore()
initButtons();
initActions();

ui->leftPanel->setPanelPosition(LeftPanel);
ui->rightPanel->setPanelPosition(RightPanel);
ui->leftPanel->setPanelPosition(Panel::LeftPanel);
ui->rightPanel->setPanelPosition(Panel::RightPanel);

ui->fullPath->clear();

ui->leftWidget->setCurrentIndex(0); // PanelWidget
ui->rightWidget->setCurrentIndex(0); // PanelWidget

_controller->panel(LeftPanel).addPanelContentsChangedListener(this);
_controller->panel(RightPanel).addPanelContentsChangedListener(this);
_controller->panel(Panel::LeftPanel).addPanelContentsChangedListener(this);
_controller->panel(Panel::RightPanel).addPanelContentsChangedListener(this);

connect(_uiThreadTimer, &QTimer::timeout, this, &CMainWindow::uiThreadTimerTick);
_uiThreadTimer->start(10);
Expand Down Expand Up @@ -909,23 +909,23 @@ void CMainWindow::addToolMenuEntriesRecursively(const CPluginProxy::MenuTree& en
CPanelDisplayController& CMainWindow::currentPanelDisplayController()
{
const auto panel = _controller->activePanelPosition();
if (panel == RightPanel)
if (panel == Panel::RightPanel)
return _rightPanelDisplayController;
else
{
assert_r(panel != UnknownPanel);
assert_r(panel != Panel::UnknownPanel);
return _leftPanelDisplayController;
}
}

CPanelDisplayController& CMainWindow::otherPanelDisplayController()
{
const auto panel = _controller->activePanelPosition();
if (panel == RightPanel)
if (panel == Panel::RightPanel)
return _leftPanelDisplayController;
else
{
assert_r(panel != UnknownPanel);
assert_r(panel != Panel::UnknownPanel);
return _rightPanelDisplayController;
}
}
Expand Down
2 changes: 1 addition & 1 deletion qt-app/src/panel/cpanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Panel CPanelWidget::panelPosition() const

void CPanelWidget::setPanelPosition(Panel p)
{
assert_r(_panelPosition == UnknownPanel);
assert_r(_panelPosition == Panel::UnknownPanel);
_panelPosition = p;

ui->_list->installEventFilter(this);
Expand Down
2 changes: 1 addition & 1 deletion qt-app/src/panel/cpanelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private slots:
QItemSelectionModel * _selectionModel = nullptr;
CFileListModel * _model = nullptr;
CFileListSortFilterProxyModel * _sortModel = nullptr;
Panel _panelPosition = UnknownPanel;
Panel _panelPosition = Panel::UnknownPanel;

QShortcut _calcDirSizeShortcut;
QShortcut _selectCurrentItemShortcut;
Expand Down
2 changes: 1 addition & 1 deletion qt-app/src/panel/filelistwidget/cfilelistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void CFileListView::addEventObserver(FileListViewEventObserver* observer)
// Sets the position (left or right) of a panel that this model represents
void CFileListView::setPanelPosition(enum Panel p)
{
assert_r(_panelPosition == UnknownPanel); // Doesn't make sense to call this method more than once
assert_r(_panelPosition == Panel::UnknownPanel); // Doesn't make sense to call this method more than once
_panelPosition = p;
}

Expand Down
2 changes: 1 addition & 1 deletion qt-app/src/panel/filelistwidget/cfilelistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CFileListView final : public QTreeView

QModelIndex _currentItemBeforeMouseClick;

enum Panel _panelPosition = UnknownPanel;
enum Panel _panelPosition = Panel::UnknownPanel;
bool _bHeaderAdjustmentRequired = true;
QPoint _singleMouseClickPos;
bool _singleMouseClickValid = false;
Expand Down
2 changes: 1 addition & 1 deletion qt-app/src/panel/filelistwidget/model/cfilelistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CFileListModel::CFileListModel(QTreeView * treeView, QObject *parent) :
// Sets the position (left or right) of a panel that this model represents
void CFileListModel::setPanelPosition(Panel p)
{
assert_r(_panel == UnknownPanel); // Doesn't make sense to call this method more than once
assert_r(_panel == Panel::UnknownPanel); // Doesn't make sense to call this method more than once
_panel = p;
}

Expand Down
2 changes: 1 addition & 1 deletion qt-app/src/panel/filelistwidget/model/cfilelistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ class CFileListModel : public QStandardItemModel
private:
CController & _controller;
QTreeView * _tree = nullptr;
Panel _panel = UnknownPanel;
Panel _panel = Panel::UnknownPanel;
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ RESTORE_COMPILER_WARNINGS
CFileListSortFilterProxyModel::CFileListSortFilterProxyModel(QObject *parent) :
QSortFilterProxyModel(parent),
_controller(CController::get()),
_panel(UnknownPanel),
_sorter(CNaturalSorting(nsaQCollator, {}))
{
}

// Sets the position (left or right) of a panel that this model represents
void CFileListSortFilterProxyModel::setPanelPosition(Panel p)
{
assert_r(_panel == UnknownPanel); // Doesn't make sense to call this method more than once
assert_r(_panel == Panel::UnknownPanel); // Doesn't make sense to call this method more than once
_panel = p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CFileListSortFilterProxyModel final : public QSortFilterProxyModel

private:
CController & _controller;
Panel _panel;
CNaturalSorting _sorter;
Panel _panel = Panel::UnknownPanel;
};

0 comments on commit 8f77c3e

Please sign in to comment.