Rename member variables.

- Move camelCase.
- Use the prefix `m_` and `mp_` for member and pointer member.
This commit is contained in:
Matthieu Gautier 2018-07-19 15:56:27 +02:00
parent e15e8cf642
commit c712a7a760
12 changed files with 88 additions and 79 deletions

View File

@ -1,7 +1,7 @@
#include "blobbuffer.h" #include "blobbuffer.h"
BlobBuffer::BlobBuffer(zim::Blob blob) BlobBuffer::BlobBuffer(zim::Blob blob)
: blob(blob) : m_blob(blob)
{ {
setData(blob.data(), blob.size()); setData(blob.data(), blob.size());
} }

View File

@ -7,11 +7,11 @@
class BlobBuffer : public QBuffer class BlobBuffer : public QBuffer
{ {
public: public:
BlobBuffer(zim::Blob blob); BlobBuffer(zim::Blob m_blob);
virtual ~BlobBuffer() = default; virtual ~BlobBuffer() = default;
private: private:
zim::Blob blob; zim::Blob m_blob;
}; };
#endif // BLOBBUFFER_H #endif // BLOBBUFFER_H

View File

@ -41,17 +41,17 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
auto font = QFont(fontName); auto font = QFont(fontName);
setFont(font); setFont(font);
mainWindow = new MainWindow; mp_mainWindow = new MainWindow;
mainWindow->show(); mp_mainWindow->show();
tabWidget = mainWindow->getTabWidget(); mp_tabWidget = mp_mainWindow->getTabWidget();
errorDialog = new QErrorMessage(mainWindow); mp_errorDialog = new QErrorMessage(mp_mainWindow);
} }
KiwixApp::~KiwixApp() KiwixApp::~KiwixApp()
{ {
delete errorDialog; delete mp_errorDialog;
delete mainWindow; delete mp_mainWindow;
} }
KiwixApp *KiwixApp::instance() KiwixApp *KiwixApp::instance()
@ -63,7 +63,7 @@ void KiwixApp::openZimFile(const QString &zimfile)
{ {
QString zimId; QString zimId;
try { try {
zimId = library.openBook(zimfile); zimId = m_library.openBook(zimfile);
} catch (const std::exception& e) { } catch (const std::exception& e) {
showMessage("Cannot open " + zimfile + ": \n" + e.what()); showMessage("Cannot open " + zimfile + ": \n" + e.what());
return; return;
@ -72,10 +72,10 @@ void KiwixApp::openZimFile(const QString &zimfile)
} }
void KiwixApp::openUrl(const QUrl &url, bool newTab) { void KiwixApp::openUrl(const QUrl &url, bool newTab) {
tabWidget->openUrl(url, newTab); mp_tabWidget->openUrl(url, newTab);
} }
void KiwixApp::showMessage(const QString &message) void KiwixApp::showMessage(const QString &message)
{ {
errorDialog->showMessage(message); mp_errorDialog->showMessage(message);
} }

View File

@ -23,21 +23,21 @@ public:
void showMessage(const QString& message); void showMessage(const QString& message);
UrlSchemeHandler* getSchemeHandler() { return &schemeHandler; } UrlSchemeHandler* getSchemeHandler() { return &m_schemeHandler; }
RequestInterceptor* getRequestInterceptor() { return &requestIntercetor; } RequestInterceptor* getRequestInterceptor() { return &m_requestInterceptor; }
Library* getLibrary() { return &library; } Library* getLibrary() { return &m_library; }
MainWindow* getMainWindow() { return mainWindow; } MainWindow* getMainWindow() { return mp_mainWindow; }
TabWidget* getTabWidget() { return tabWidget; } TabWidget* getTabWidget() { return mp_tabWidget; }
private: private:
Library library; Library m_library;
MainWindow* mainWindow; MainWindow* mp_mainWindow;
TabWidget* tabWidget; TabWidget* mp_tabWidget;
QErrorMessage* errorDialog; QErrorMessage* mp_errorDialog;
UrlSchemeHandler schemeHandler; UrlSchemeHandler m_schemeHandler;
RequestInterceptor requestIntercetor; RequestInterceptor m_requestInterceptor;
}; };
#endif // KIWIXAPP_H #endif // KIWIXAPP_H

View File

@ -8,8 +8,8 @@ Library::Library()
QString Library::openBook(const QString &zimPath) QString Library::openBook(const QString &zimPath)
{ {
for(auto it=readers_map.begin(); for(auto it=m_readersMap.begin();
it != readers_map.end(); it != m_readersMap.end();
it++) it++)
{ {
if(QString::fromStdString(it->second->getZimFilePath()) == zimPath) if(QString::fromStdString(it->second->getZimFilePath()) == zimPath)
@ -19,14 +19,14 @@ QString Library::openBook(const QString &zimPath)
const std::string zimPath_ = zimPath.toLocal8Bit().constData(); const std::string zimPath_ = zimPath.toLocal8Bit().constData();
auto reader = std::shared_ptr<kiwix::Reader>(new kiwix::Reader(zimPath_)); auto reader = std::shared_ptr<kiwix::Reader>(new kiwix::Reader(zimPath_));
auto id = QString::fromStdString(reader->getId() + ".zim"); auto id = QString::fromStdString(reader->getId() + ".zim");
readers_map[id] = reader; m_readersMap[id] = reader;
return id; return id;
} }
std::shared_ptr<kiwix::Reader> Library::getReader(const QString &zimId) std::shared_ptr<kiwix::Reader> Library::getReader(const QString &zimId)
{ {
auto it = readers_map.find(zimId); auto it = m_readersMap.find(zimId);
if (it != readers_map.end()) if (it != m_readersMap.end())
return it->second; return it->second;
return nullptr; return nullptr;
} }

View File

@ -12,7 +12,7 @@ public:
QString openBook(const QString& zimPath); QString openBook(const QString& zimPath);
std::shared_ptr<kiwix::Reader> getReader(const QString& zimId); std::shared_ptr<kiwix::Reader> getReader(const QString& zimId);
private: private:
std::map<QString, std::shared_ptr<kiwix::Reader>> readers_map; std::map<QString, std::shared_ptr<kiwix::Reader>> m_readersMap;
}; };
#endif // LIBRARY_H #endif // LIBRARY_H

View File

@ -9,10 +9,10 @@
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) mp_ui(new Ui::MainWindow)
{ {
ui->setupUi(this); mp_ui->setupUi(this);
ui->tabWidget->tabBar()->setExpanding(false); mp_ui->tabWidget->tabBar()->setExpanding(false);
#if !SYSTEMTITLEBAR #if !SYSTEMTITLEBAR
setWindowFlags(Qt::Window | Qt::CustomizeWindowHint); setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
#endif #endif
@ -20,11 +20,11 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete mp_ui;
} }
TabWidget* MainWindow::getTabWidget() TabWidget* MainWindow::getTabWidget()
{ {
return ui->tabWidget; return mp_ui->tabWidget;
} }

View File

@ -20,7 +20,7 @@ public:
TabWidget* getTabWidget(); TabWidget* getTabWidget();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *mp_ui;
}; };

View File

@ -7,61 +7,69 @@
TopWidget::TopWidget(QWidget *parent) : TopWidget::TopWidget(QWidget *parent) :
QToolBar(parent), QToolBar(parent),
fullScreen(false) m_fullScreen(false)
{ {
m_historyBackAction = new QAction(this); mp_historyBackAction = new QAction(this);
m_historyBackAction->setIcon(QIcon(":/icons/back.svg")); mp_historyBackAction->setIcon(QIcon(":/icons/back.svg"));
m_historyBackAction->setText("back"); mp_historyBackAction->setText("back");
m_historyBackAction->setToolTip("back"); mp_historyBackAction->setToolTip("back");
connect(m_historyBackAction, &QAction::triggered, [this](){ connect(mp_historyBackAction, &QAction::triggered, [this](){
KiwixApp::instance()->getTabWidget()->triggerWebPageAction(QWebEnginePage::Back); KiwixApp::instance()->getTabWidget()->triggerWebPageAction(QWebEnginePage::Back);
}); });
addAction(m_historyBackAction); addAction(mp_historyBackAction);
m_historyForwardAction = new QAction(this); mp_historyForwardAction = new QAction(this);
m_historyForwardAction->setIcon(QIcon(":/icons/forward.svg")); mp_historyForwardAction->setIcon(QIcon(":/icons/forward.svg"));
m_historyForwardAction->setText("forward"); mp_historyForwardAction->setText("forward");
m_historyForwardAction->setToolTip("forward"); mp_historyForwardAction->setToolTip("forward");
connect(m_historyForwardAction, &QAction::triggered, [this](){ connect(mp_historyForwardAction, &QAction::triggered, [this](){
KiwixApp::instance()->getTabWidget()->triggerWebPageAction(QWebEnginePage::Forward); KiwixApp::instance()->getTabWidget()->triggerWebPageAction(QWebEnginePage::Forward);
}); });
addAction(m_historyForwardAction); addAction(mp_historyForwardAction);
addSeparator(); addSeparator();
addWidget(&searchEntry); addWidget(&m_searchEntry);
addSeparator(); addSeparator();
#if !SYSTEMTITLEBAR #if !SYSTEMTITLEBAR
addAction(QIcon(":/icons/minimize.svg"), "minimize", parent, SLOT(showMinimized())); addAction(QIcon(":/icons/minimize.svg"), "minimize", parent, SLOT(showMinimized()));
#endif #endif
fullScreenAction = addAction(QIcon(":/icons/full-screen-enter.svg"), "fullscreen", this, SLOT(toggleFullScreen())); mp_fullScreenAction = addAction(QIcon(":/icons/full-screen-enter.svg"), "fullscreen", this, SLOT(toggleFullScreen()));
normalScreenAction = addAction(QIcon(":/icons/full-screen-exit.svg"), "unfullscreen", this, SLOT(toggleFullScreen())); mp_normalScreenAction = addAction(QIcon(":/icons/full-screen-exit.svg"), "unfullscreen", this, SLOT(toggleFullScreen()));
normalScreenAction->setVisible(false); mp_normalScreenAction->setVisible(false);
#if !SYSTEMTITLEBAR #if !SYSTEMTITLEBAR
addAction(QIcon(":/icons/close.svg"), "close", parent, SLOT(close())); addAction(QIcon(":/icons/close.svg"), "close", parent, SLOT(close()));
#endif #endif
setMovable(false); setMovable(false);
} }
TopWidget::~TopWidget()
{
delete mp_historyBackAction;
delete mp_historyForwardAction;
delete mp_fullScreenAction;
delete mp_normalScreenAction;
}
void TopWidget::toggleFullScreen() { void TopWidget::toggleFullScreen() {
if (fullScreen) if (m_fullScreen)
parentWidget()->showNormal(); parentWidget()->showNormal();
else else
parentWidget()->showFullScreen(); parentWidget()->showFullScreen();
fullScreen = !fullScreen; m_fullScreen = !m_fullScreen;
fullScreenAction->setVisible(!fullScreen); mp_fullScreenAction->setVisible(!m_fullScreen);
normalScreenAction->setVisible(fullScreen); mp_normalScreenAction->setVisible(m_fullScreen);
} }
void TopWidget::handleWebActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled) void TopWidget::handleWebActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled)
{ {
switch (action) { switch (action) {
case QWebEnginePage::Back: case QWebEnginePage::Back:
m_historyBackAction->setEnabled(enabled); mp_historyBackAction->setEnabled(enabled);
break; break;
case QWebEnginePage::Forward: case QWebEnginePage::Forward:
m_historyForwardAction->setEnabled(enabled); mp_historyForwardAction->setEnabled(enabled);
break; break;
default: default:
break; break;
@ -73,17 +81,17 @@ void TopWidget::mousePressEvent(QMouseEvent *event) {
if(event->button() != Qt::LeftButton) if(event->button() != Qt::LeftButton)
return; return;
m_pCursor = event->globalPos() + frameGeometry().topLeft() - parentWidget()->frameGeometry().topLeft(); m_cursorPos = event->globalPos() + frameGeometry().topLeft() - parentWidget()->frameGeometry().topLeft();
timestamp = event->timestamp(); m_timestamp = event->timestamp();
event->accept(); event->accept();
} }
void TopWidget::mouseMoveEvent(QMouseEvent *event) { void TopWidget::mouseMoveEvent(QMouseEvent *event) {
if(event->timestamp() <= timestamp) if(event->timestamp() <= m_timestamp)
return; return;
timestamp = event->timestamp(); m_timestamp = event->timestamp();
auto delta = event->globalPos() - m_pCursor; auto delta = event->globalPos() - m_cursorPos;
parentWidget()->move(delta); parentWidget()->move(delta);
event->accept(); event->accept();
} }

View File

@ -10,20 +10,21 @@ class TopWidget : public QToolBar
Q_OBJECT Q_OBJECT
public: public:
explicit TopWidget(QWidget *parent = nullptr); explicit TopWidget(QWidget *parent = nullptr);
virtual ~TopWidget();
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
private: private:
QLineEdit searchEntry; QLineEdit m_searchEntry;
QAction* m_historyBackAction; QAction* mp_historyBackAction;
QAction* m_historyForwardAction; QAction* mp_historyForwardAction;
QAction* fullScreenAction; QAction* mp_fullScreenAction;
QAction* normalScreenAction; QAction* mp_normalScreenAction;
bool fullScreen; bool m_fullScreen;
QPoint m_pCursor; QPoint m_cursorPos;
ulong timestamp; ulong m_timestamp;
protected slots: protected slots:
void toggleFullScreen(); void toggleFullScreen();

View File

@ -35,15 +35,15 @@ QWebEngineView* WebView::createWindow(QWebEnginePage::WebWindowType type)
} }
void WebView::onUrlChanged(const QUrl& url) { void WebView::onUrlChanged(const QUrl& url) {
if (currentHost != url.host() ) { if (m_currentHost != url.host() ) {
currentHost = url.host(); m_currentHost = url.host();
auto app = KiwixApp::instance(); auto app = KiwixApp::instance();
auto reader = app->getLibrary()->getReader(currentHost); auto reader = app->getLibrary()->getReader(m_currentHost);
std::string favicon, _mimetype; std::string favicon, _mimetype;
reader->getFavicon(favicon, _mimetype); reader->getFavicon(favicon, _mimetype);
QPixmap pixmap; QPixmap pixmap;
pixmap.loadFromData((const uchar*)favicon.data(), favicon.size()); pixmap.loadFromData((const uchar*)favicon.data(), favicon.size());
_icon = QIcon(pixmap); m_icon = QIcon(pixmap);
emit iconChanged(_icon); emit iconChanged(m_icon);
} }
} }

View File

@ -16,7 +16,7 @@ public:
virtual ~WebView(); virtual ~WebView();
bool isWebActionEnabled(QWebEnginePage::WebAction webAction) const; bool isWebActionEnabled(QWebEnginePage::WebAction webAction) const;
const QIcon &icon() { return _icon; } const QIcon &icon() { return m_icon; }
public slots: public slots:
void onUrlChanged(const QUrl& url); void onUrlChanged(const QUrl& url);
@ -26,8 +26,8 @@ signals:
protected: protected:
virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type); virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type);
QString currentHost; QString m_currentHost;
QIcon _icon; QIcon m_icon;
}; };
#endif // WEBVIEW_H #endif // WEBVIEW_H