/CMain.cpp
C++ | 2264 lines | 1636 code | 373 blank | 255 comment | 105 complexity | f3ce89ba9bd20af46d091e51c19c0b1a MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /**
- * \file CMain.h
- * \brief main window
- */
- #include "CMain.h"
- #include "Forms/CLinkProperties.h"
- //------------------------------------------------------------------------------
- CMain::CMain(
- QWidget *a_parent
- ) :
- QDialog (a_parent),
- #if defined(Q_OS_X11)
- _m_hlHAl (a_parent),
- #endif
- _m_tabLinks (NULL),
- _m_dbDatabase (),
- _m_smapToolButtons (),
- _m_smapLinks (),
- _m_tmSystemUsage (),
- _m_tmTemperatureUsage(),
- _m_tmCurrentDateTime (),
- _m_nmNetworkManager (this),
- _m_bIsAllowWrap (true),
- _m_bIsLinkSwap (false),
- _m_btnLinkFrom (NULL),
- _m_mnuDirs (),
- _m_ptMousePos ()
- {
- // backup DB
- {
- CxBackup backup(CxBackup::bpDaily);
- try {
- std::tstring_t sBackupFilePath;
- backup.fileExec(CxPath::exe() + xT(DB_FILE_EXT),
- CxPath::exeDir() + CxConst::slash() + xT(BACKUP_DIR_NAME),
- &sBackupFilePath);
- }
- catch (const CxException &e) {
- cQString csMsg = QString("CxBackup: ") + qS2QS(e.what());
- QMessageBox::warning(this, qApp->applicationName(), csMsg, QMessageBox::Ok);
- }
- }
- _construct();
- _settingsLoad();
- }
- //------------------------------------------------------------------------------
- /*******************************************************************************
- * CMain
- *
- *******************************************************************************/
- //------------------------------------------------------------------------------
- void
- CMain::_construct() {
- ui.setupUi(this);
- //--------------------------------------------------
- // settings DB
- {
- bool bRv = QSqlDatabase::isDriverAvailable("QSQLITE");
- qCHECK_DO(false == bRv, qMSG(QSqlDatabase().lastError().text()); return;);
- _m_dbDatabase = QSqlDatabase::addDatabase("QSQLITE");
- _m_dbDatabase.setDatabaseName(DB_FILE_PATH);
- bRv = _m_dbDatabase.open();
- qCHECK_REF(bRv, _m_dbDatabase);
- {
- QSqlQuery qryTable(_m_dbDatabase);
- cQString csSql = \
- "CREATE TABLE IF NOT EXISTS t_tabs"
- "( "
- " f_id INTEGER PRIMARY KEY AUTOINCREMENT "
- " NOT NULL "
- " UNIQUE, "
- " f_name VARCHAR(64) NOT NULL "
- " UNIQUE "
- ")";
- bRv = qryTable.exec(csSql);
- qCHECK_REF(bRv, qryTable);
- }
- {
- QSqlQuery qryTable(_m_dbDatabase);
- cQString csSql = \
- "CREATE TABLE IF NOT EXISTS t_main"
- "( "
- " f_id INTEGER PRIMARY KEY AUTOINCREMENT "
- " NOT NULL "
- " UNIQUE, "
- " f_tab_index INTEGER NOT NULL "
- " REFERENCES t_tabs (f_id) "
- " ON DELETE RESTRICT "
- " ON UPDATE CASCADE, "
- " f_link_index INTEGER NOT NULL, "
- " f_text VARCHAR(64), "
- " f_file_path VARCHAR(255), "
- " f_file_params VARCHAR(64) "
- ")";
- bRv = qryTable.exec(csSql);
- qCHECK_REF(bRv, qryTable);
- }
- }
- //--------------------------------------------------
- // CMain
- {
- setWindowTitle(APP_NAME);
- // remove window title bar, taskbar
- {
- Qt::WindowFlags wfFlags = windowFlags();
- wfFlags |= Qt::ToolTip;
- setWindowFlags(wfFlags);
- }
- // wrap window
- {
- cint ciTitleHeight = ui.frTitle->geometry().height();
- cint ciTargetHeight = ciTitleHeight;
- setFixedHeight(ciTargetHeight);
- }
- CUtils::widgetAlwaysOnTop(this, true);
- }
- //--------------------------------------------------
- // header
- {
- // tbtnMenuDirs
- _menuDirs_Create(&_m_mnuDirs, ui.tbtnMenuDirs);
- ui.tbtnMenuDirs->setPopupMode(QToolButton::InstantPopup);
- ui.tbtnMenuDirs->setMenu(&_m_mnuDirs);
- ui.tbtnMenuDirs->setIcon(QProxyStyle().standardIcon(QStyle::SP_DirHomeIcon));
- #if 0
- // tbtnMenuRun
- ui.tbtnMenuRun->setPopupMode(QToolButton::InstantPopup);
- ui.tbtnMenuRun->setIcon(QProxyStyle().standardIcon(QStyle::SP_CommandLink));
- connect(ui.tbtnMenuRun, SIGNAL(pressed()),
- this, SLOT (tbtnMenuRun_OnPressed);
- #endif
- // btnClose
- ui.btnClose->setText("");
- ui.btnClose->setIcon(QProxyStyle().standardIcon(QStyle::SP_TitleBarCloseButton));
- // lblTemperatureUsage
- ui.lblTemperatureUsage->setText("<b>T:</b> - ");
- // prgCpuUsage, prgMemoryUsage
- ui.prgCpuUsage->setFormat("");
- ui.prgCpuUsage->setOrientation(Qt::Vertical);
- ui.prgCpuUsage->setMaximum(0);
- ui.prgCpuUsage->setMaximum(100);
- ui.prgCpuUsage->setValue(0);
- ui.prgMemoryUsage->setFormat("");
- ui.prgMemoryUsage->setOrientation(Qt::Vertical);
- ui.prgMemoryUsage->setMaximum(0);
- ui.prgMemoryUsage->setMaximum(100);
- ui.prgMemoryUsage->setValue(0);
- // update usage
- systemUsage_OnTimeout();
- }
- /***************************************************************************
- * setup slots
- *
- ***************************************************************************/
- #if defined(Q_OS_X11)
- //--------------------------------------------------
- // insert/remove device events
- {
- connect(&_m_hlHAl, &CMain::signal_OnAdded,
- this, &CMain::slot_Hal_OnAdded);
- connect(&_m_hlHAl, &CMain::signal_OnRemoved,
- this, &CMain::slot_Hal_OnRemoved);
- }
- #endif
- //--------------------------------------------------
- // signal mappers
- {
- connect(&_m_smapToolButtons, SIGNAL(mapped(QWidget *)),
- this, SLOT (btnVolume_OnClicked(QWidget *)));
- connect(&_m_smapLinks, SIGNAL(mapped(QWidget *)),
- this, SLOT (btnLink_OnClicked(QWidget *)));
- }
- //--------------------------------------------------
- // "My computer" button
- {
- ui.tbtnMyComputer->setGeometry( 0 * BUTTON_WIDTH, BUTTON_MARGIN, BUTTON_WIDTH, BUTTON_HEIGHT);
- ui.tbtnMyComputer->setAutoRaise(true);
- ui.tbtnMyComputer->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- _m_smapToolButtons.setMapping(ui.tbtnMyComputer, ui.tbtnMyComputer);
- connect(ui.tbtnMyComputer, &QToolButton::clicked,
- this, &CMain::mnuDirs_OnMyComputer);
- // ui.tbtnMyComputer->setMenu();
- }
- //--------------------------------------------------
- // volume buttons
- {
- // fill container
- _m_vtbVolumes.push_back(ui.tbtnVolume1);
- _m_vtbVolumes.push_back(ui.tbtnVolume2);
- _m_vtbVolumes.push_back(ui.tbtnVolume3);
- _m_vtbVolumes.push_back(ui.tbtnVolume4);
- _m_vtbVolumes.push_back(ui.tbtnVolume5);
- _m_vtbVolumes.push_back(ui.tbtnVolume6);
- _m_vtbVolumes.push_back(ui.tbtnVolume7);
- _m_vtbVolumes.push_back(ui.tbtnVolume8);
- // set options
- for (int i = 0; i < _m_vtbVolumes.size(); ++ i) {
- // start from 2-nd toolbutton
- _m_vtbVolumes.at(i)->setGeometry((i + 1) * BUTTON_WIDTH, BUTTON_MARGIN, BUTTON_WIDTH, BUTTON_HEIGHT);
- _m_vtbVolumes.at(i)->setAutoRaise(true);
- _m_vtbVolumes.at(i)->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- _m_smapToolButtons.setMapping(_m_vtbVolumes.at(i), _m_vtbVolumes.at(i));
- connect(_m_vtbVolumes.at(i), SIGNAL(clicked()),
- &_m_smapToolButtons, SLOT (map()));
- }
- _volumes_Rebuild(&_m_vtbVolumes);
- }
- //--------------------------------------------------
- // CMain
- {
- connect(this, &CMain::signal_title_LClicked,
- this, &CMain::title_OnLClicked);
- connect(this, &CMain::signal_title_RClicked,
- this, &CMain::title_OnRClicked);
- ui.frTitle->installEventFilter(this);
- connect(&_m_tmSystemUsage, &QTimer::timeout,
- this, &CMain::systemUsage_OnTimeout);
- // set timeout only for the 1-st launch
- _m_tmSystemUsage.start(SYTEM_USAGE_STARTUP_TIMEOUT);
- connect(&_m_tmTemperatureUsage, &QTimer::timeout,
- this, &CMain::weatherTemp_OnTimeout);
- // set timeout only for the 1-st launch
- _m_tmTemperatureUsage.start(SYTEM_USAGE_STARTUP_TIMEOUT);
- connect(&_m_tmCurrentDateTime, &QTimer::timeout,
- this, &CMain::currentDate_OnTimeout);
- _m_tmCurrentDateTime.start(CURRENT_DATETIME_TIMEOUT);
- connect(&_m_nmNetworkManager, &QNetworkAccessManager::finished,
- this, &CMain::networkReply_OnFinished);
- connect(ui.btnClose, &QToolButton::clicked,
- this, &CMain::btnClose_OnClicked);
- }
- //--------------------------------------------------
- // _m_tabLinks
- {
- _m_tabLinks = new CTabWidgetEx(this);
- xTEST_PTR(_m_tabLinks);
- _m_tabLinks->setParent(this);
- _m_tabLinks->setMovable(true);
- _m_tabLinks->setGeometry(0, TITLEBAR_HEIGHT * 2, TABLINKS_WIDTH, TABLINKS_HEIGHT);
- _m_tabLinks->setContextMenuPolicy(Qt::CustomContextMenu);
- _m_tabLinks->setCurrentIndex(0); // 0 - first tab
- _m_tabLinks->setVisible(true);
- connect(_m_tabLinks->tabBarEx(), &QTabBar::tabMoved,
- this, &CMain::tabLinks_OnMoved);
- connect(_m_tabLinks, SIGNAL(customContextMenuRequested(const QPoint &)),
- SLOT (mnuLinks_OnShow(const QPoint &)));
- }
- //--------------------------------------------------
- // create tab pages
- {
- // from DB
- QSqlQuery qryTabs(_m_dbDatabase);
- cQString csSql = \
- "SELECT f_name FROM t_tabs";
- bool bRv = qryTabs.exec(csSql);
- qCHECK_REF(bRv, qryTabs);
- // create
- for ( ; true == qryTabs.next(); ) {
- cQString csTabName = qryTabs.value(0).toString(); // 0 - f_name
- _tabPageShow(csTabName);
- }
- }
- //--------------------------------------------------
- // statusbar
- {
- // font
- {
- QFont fntFont( ui.lblDayOfWeek->font() );
- fntFont.setPointSize( ui.lblDayOfWeek->font().pointSize() );
- fntFont.setBold(false);
- ui.lblDayOfWeek->setFont(fntFont);
- }
- // ui.lblDayOfWeek->setAlignment(Qt::AlignCenter);
- currentDate_OnTimeout();
- }
- }
- //------------------------------------------------------------------------------
- void
- CMain::_destruct() {
- _settingsSave();
- }
- //------------------------------------------------------------------------------
- void
- CMain::title_OnLClicked() {
- int iTitleHeight = 0;
- int iTargetHeight = 0;
- if (TITLEBAR_HEIGHT == height()) {
- // unwrap main window
- iTitleHeight = ui.frTitle->geometry().height();
- iTargetHeight = iTitleHeight + TITLEBAR_HEIGHT + _m_tabLinks->height();
- } else {
- // wrap main window
- qCHECK_DO(false == _m_bIsAllowWrap, return);
- iTitleHeight = ui.frTitle->geometry().height();
- iTargetHeight = iTitleHeight;
- }
- setFixedWidth(width());
- setFixedHeight(iTargetHeight);
- }
- //------------------------------------------------------------------------------
- void
- CMain::title_OnRClicked() {
- static bool s_bFlagIsMinimize = false;
- s_bFlagIsMinimize = !s_bFlagIsMinimize;
- // TODO: CUtils::desktopWindowsMinimize(s_bFlagIsMinimize);
- }
- //------------------------------------------------------------------------------
- void
- CMain::tbtnMenuRun_OnPressed() {
- // wrap window
- {
- cint iTitleHeight = ui.frTitle->geometry().height();
- cint iTargetHeight = iTitleHeight;
- setFixedHeight(iTargetHeight);
- }
- QClipboard *pcbClipboard = QApplication::clipboard();
- xTEST_PTR(pcbClipboard);
- cQString csProgram = pcbClipboard->text().trimmed();
- cQString cslArgs; // TODO: cslArgs
- qCHECK_DO(true == csProgram.isEmpty(), return);
- QString sDir = QString("file:///%1")
- .arg(csProgram);
- bool bRv = QDesktopServices::openUrl( QUrl(sDir) );
- xTEST_EQ(true, bRv);
- }
- //------------------------------------------------------------------------------
- /*******************************************************************************
- * protected
- *
- *******************************************************************************/
- //------------------------------------------------------------------------------
- /*virtual*/
- bool
- CMain::eventFilter(
- QObject *a_object,
- QEvent *a_event
- )
- {
- // title clicks
- if (ui.frTitle == a_object) {
- if (QEvent::MouseButtonPress == a_event->type()) {
- QMouseEvent *mouseEvent = static_cast<QMouseEvent *>( a_event );
- if (Qt::LeftButton == mouseEvent->button()) {
- emit signal_title_LClicked();
- }
- else if (Qt::RightButton == mouseEvent->button()) {
- emit signal_title_RClicked();
- }
- else {
- xNA;
- }
- }
- }
- return false;
- }
- //------------------------------------------------------------------------------
- /*virtual*/
- void
- CMain::focusInEvent(
- QFocusEvent *a_event
- )
- {
- if (true == a_event->gotFocus()) {
- _volumes_Rebuild(&_m_vtbVolumes);
- }
- QWidget::focusInEvent(a_event);
- }
- //------------------------------------------------------------------------------
- /*virtual*/
- void
- CMain::focusOutEvent(
- QFocusEvent *a_event
- )
- {
- if (true == a_event->lostFocus()) {
- if (TITLEBAR_HEIGHT < height()) {
- title_OnLClicked();
- }
- }
- QWidget::focusOutEvent(a_event);
- }
- //------------------------------------------------------------------------------
- /* virtual */
- void
- CMain::closeEvent(
- QCloseEvent *a_event
- )
- {
- _destruct();
- a_event->accept();
- }
- //------------------------------------------------------------------------------
- /*******************************************************************************
- * header - insert / remove device events
- *
- *******************************************************************************/
- //------------------------------------------------------------------------------
- #if defined(Q_OS_WIN)
- /* virtual */
- bool
- CMain::nativeEvent(
- cQByteArray &a_eventType,
- void *a_message,
- long *a_result
- )
- {
- /*
- * Platform Event Type Identifier Message Type Result Type
- * Windows "windows_generic_MSG" MSG * LRESULT
- */
- MSG *pmsgMsg = static_cast<MSG *>(a_message);
- Q_UNUSED(a_result);
- xCHECK_RET(NULL == pmsgMsg, false);
- // inserting volume
- if (WM_DEVICECHANGE == pmsgMsg->message &&
- DBT_DEVICEARRIVAL == pmsgMsg->wParam
- )
- {
- _volumes_Rebuild(&_m_vtbVolumes);
- return true;
- }
- // removing volume
- if (WM_DEVICECHANGE == pmsgMsg->message &&
- DBT_DEVICEREMOVECOMPLETE == pmsgMsg->wParam
- )
- {
- _volumes_Rebuild(&_m_vtbVolumes);
- return true;
- }
- return QWidget::nativeEvent(a_eventType, a_message, a_result);
- }
- #elif defined(Q_OS_X11)
- //------------------------------------------------------------------------------
- // HAL
- void
- CMain::slot_Hal_OnAdded(cQString &dev) {
- qDebug() << __FUNCTION__ << dev;
- _volumes_Rebuild(&_m_vtbVolumes);
- }
- //------------------------------------------------------------------------------
- void
- CMain::slot_Hal_OnRemoved(cQString &dev) {
- qDebug() << __FUNCTION__ << dev;
- _volumes_Rebuild(&_m_vtbVolumes);
- }
- //------------------------------------------------------------------------------
- #endif // Q_OS_X11
- /*******************************************************************************
- * header - GUI
- *
- *******************************************************************************/
- //------------------------------------------------------------------------------
- void
- CMain::systemUsage_OnTimeout() {
- CxSystemInfo info;
- const ulong_t culCpuUsage = info.cpuUsage();
- const ulong_t culRamUsage = info.ramUsage();
- cQString csCpuUsage = QString("<b>CPU:</b> %1%").arg(culCpuUsage);
- cQString csMemoryUsage = QString("<b>RAM:</b> %1%").arg(culRamUsage);
- // prgCpuUsage
- ui.prgCpuUsage->setValue(culCpuUsage);
- ui.prgCpuUsage->setToolTip(csCpuUsage);
- // prgMemoryUsage
- ui.prgMemoryUsage->setValue(culRamUsage);
- ui.prgMemoryUsage->setToolTip(csMemoryUsage);
- }
- //------------------------------------------------------------------------------
- void
- CMain::weatherTemp_OnTimeout() {
- _m_tmTemperatureUsage.setInterval(WEATHER_TEMPR_CHECK_TIMEOUT);
- #if 0
- /**
- * Google API
- *
- * FAQ:
- * HTTP GET: http://www.google.com/ig/api?weather=kiev&hl=en
- */
- QUrl urUrl("http://www.google.com/ig/api");
- urUrl.addEncodedQueryItem("weather", QUrl::toPercentEncoding(WEATHER_TEMPR_CITY));
- urUrl.addEncodedQueryItem("hl", "en");
- #endif
- /**
- * Yahoo API
- *
- * FAQ: http://developer.yahoo.com/weather/
- * HTTP GET: http://weather.yahooapis.com/forecastrss?w=924938&u=c
- */
- QUrl urUrl("http://weather.yahooapis.com/forecastrss?w=924938&u=c");
- urUrl.toEncoded();
- QNetworkRequest nrRequest;
- nrRequest.setUrl(urUrl);
- #if 1
- _m_nmNetworkManager.get(nrRequest);
- #endif
- }
- //------------------------------------------------------------------------------
- void
- CMain::currentDate_OnTimeout() {
- cQString csDate = QDate().currentDate().toString("dd.MM.yyyy");
- cQString csDayOfWeek = QDate().currentDate().toString("ddd");
- cQString csTime = QTime().currentTime().toString("H:mm");
- cQString csDateTimeFormated = QString("<b>%1</b> <u>%2</u> %3")
- .arg(csTime)
- .arg(csDayOfWeek)
- .arg(csDate);
- ui.lblDayOfWeek->setText(csDateTimeFormated);
- }
- //------------------------------------------------------------------------------
- void
- CMain::networkReply_OnFinished(
- QNetworkReply *a_pnrReply
- )
- {
- QString sRv;
- cint ciStatus = a_pnrReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- if (200 == ciStatus) {
- cQString csText = QString::fromUtf8(a_pnrReply->readAll());
- sRv = QString("<b>T:</b> %1").arg( _yahooReplyParse(csText) );
- } else {
- qDebug() << "ciStatus: " << ciStatus;
- sRv = QString("<b>T:</b> %1").arg("-");
- }
- ui.lblTemperatureUsage->setText(sRv);
- a_pnrReply->deleteLater();
- }
- //------------------------------------------------------------------------------
- QString
- CMain::_googleReplyParse(
- cQString &a_csXml
- )
- {
- QXmlStreamReader xml(a_csXml);
- while (!xml.atEnd()) {
- xml.readNext();
- qCHECK_DO(QXmlStreamReader::StartElement != xml.tokenType(), continue);
- // Parse current weather conditions
- if (xml.name() == "current_conditions") {
- while (!xml.atEnd()) {
- xml.readNext();
- if ("current_conditions" == xml.name()) {
- break;
- }
- if (QXmlStreamReader::StartElement == xml.tokenType()) {
- if ("temp_c" == xml.name()) {
- QString sTempr = xml.attributes().value("data").toString().trimmed();
- xCHECK_RET(true == sTempr.isEmpty(), "-");
- // add "+" prefix to temperature
- if ("-" == sTempr.at(0)) {
- xNA;
- } else {
- sTempr = "+" + sTempr;
- }
- return QString("%1%2%3")
- .arg(sTempr)
- .arg(QChar(176))
- .arg("C");
- }
- }
- }
- }
- }
- return "-";
- }
- //------------------------------------------------------------------------------
- QString
- CMain::_yahooReplyParse(
- cQString &a_csXml
- )
- {
- QXmlStreamReader xml(a_csXml);
- while (!xml.atEnd()) {
- xml.readNext();
- qCHECK_DO(QXmlStreamReader::StartElement != xml.tokenType(), continue);
- // parse:
- // <yweather:condition text="Light Rain Shower" code="11" temp="5"
- // date="Thu, 11 Oct 2012 9:58 am EEST" />
- if (xml.name() == "condition") {
- QString sTempr = xml.attributes().value("temp").toString().trimmed();
- qCHECK_RET(true == sTempr.isEmpty(), "-");
- // add "+" prefix to temperature
- if ("-" == sTempr.at(0)) {
- xNA;
- } else {
- sTempr = "+" + sTempr;
- }
- return QString("%1%2%3")
- .arg(sTempr)
- .arg(QChar(176))
- .arg("C");
- }
- }
- return "-";
- }
- //------------------------------------------------------------------------------
- void
- CMain::_settingsLoad() {
- QSize szSize;
- QPoint pnPosition;
- {
- QSettings stSettings(INI_FILE_PATH, QSettings::IniFormat, this);
- stSettings.beginGroup("main");
- szSize = stSettings.value("size", APP_SIZE).toSize();
- pnPosition = stSettings.value("position", QPoint(200, 200)).toPoint();
- stSettings.endGroup();
- }
- // apply settings
- {
- resize(szSize);
- move(pnPosition);
- }
- }
- //------------------------------------------------------------------------------
- void
- CMain::_settingsSave() {
- QSettings stSettings(INI_FILE_PATH, QSettings::IniFormat, this);
- stSettings.beginGroup("main");
- stSettings.setValue("position", pos());
- stSettings.setValue("size", size());
- stSettings.endGroup();
- }
- //------------------------------------------------------------------------------
- void
- CMain::btnClose_OnClicked() {
- close();
- }
- //------------------------------------------------------------------------------
- /*******************************************************************************
- * CLinkButton
- *
- *******************************************************************************/
- //------------------------------------------------------------------------------
- void
- CMain::_tabPageAddEmpty(
- cQString &a_tabName
- )
- {
- // to DB (t_tabs)
- {
- QSqlQuery qryInsert(_m_dbDatabase);
- cQString csSql = \
- "INSERT INTO t_tabs (f_name) VALUES (:p_tab_name)";
- bool bRv = qryInsert.prepare(csSql);
- qCHECK_REF(bRv, qryInsert)
- qryInsert.bindValue(":p_tab_name", a_tabName);
- bRv = qryInsert.exec();
- qCHECK_REF(bRv, qryInsert);
- }
- // DB (t_main)
- {
- cint _ciTabIndex = _m_tabLinks->count();
- for (int x = 0, index = 0; x < TAB_X; ++ x) {
- for (int y = 0; y < TAB_Y; ++ y, ++ index) {
- cint ciTabIndex = _ciTabIndex;
- cint ciLinkIndex = index;
- cQString csText;
- cQString csFilePath;
- cQString csFileParams;
- QSqlQuery qryInsert(_m_dbDatabase);
- cQString csSql = \
- "INSERT INTO "
- " t_main (f_tab_index, f_link_index, f_text, f_file_path, f_file_params) "
- "VALUES "
- " (:p_tab_index, :p_link_index, :p_text, :p_file_path, :p_file_params)";
- bool bRv = qryInsert.prepare(csSql);
- qCHECK_REF(bRv, qryInsert)
- qryInsert.bindValue(":p_tab_index", ciTabIndex);
- qryInsert.bindValue(":p_link_index", ciLinkIndex);
- qryInsert.bindValue(":p_text", csText);
- qryInsert.bindValue(":p_file_path", csFilePath);
- qryInsert.bindValue(":p_file_params", csFileParams);
- bRv = qryInsert.exec();
- qCHECK_REF(bRv, qryInsert);
- }
- }
- }
- }
- //------------------------------------------------------------------------------
- void
- CMain::_tabPageShow(
- cQString &a_tabName
- )
- {
- cint _ciTabIndex = _m_tabLinks->addTab(new QWidget(), a_tabName);
- // build current tab (4x10)
- for (int x = 0, index = 0; x < TAB_X; ++ x) {
- for (int y = 0; y < TAB_Y; ++ y, ++ index) {
- cint ciTabIndex = _ciTabIndex;
- cint ciLinkIndex = index;
- QString sText;
- QString sFilePath;
- QString sFileParams;
- // DB (get link data from DB)
- {
- QSqlQuery qryLinks(_m_dbDatabase);
- cQString csSql = \
- "SELECT f_text, f_file_path, f_file_params "
- " FROM t_main "
- "WHERE "
- " (f_tab_index=:p_tab_index AND f_link_index=:p_link_index)";
- bool bRv = qryLinks.prepare(csSql);
- qCHECK_REF(bRv, qryLinks)
- qryLinks.bindValue(":p_tab_index", ciTabIndex);
- qryLinks.bindValue(":p_link_index", ciLinkIndex);
- bRv = qryLinks.exec();
- qCHECK_REF(bRv, qryLinks);
- // assignment
- if (true == qryLinks.next()) {
- sText = qryLinks.value(0).toString(); /* 0 - f_text */
- sFilePath = qryLinks.value(1).toString(); /* 1 - f_file_path */
- sFileParams = qryLinks.value(2).toString(); /* 2 - f_file_params */
- } else {
- sText.clear();
- sFilePath.clear();
- sFileParams.clear();
- }
- }
- // Ui
- {
- // create link
- CLinkButton *pbtnLink = new CLinkButton;
- xTEST_PTR(pbtnLink);
- pbtnLink->setGeometry(x * SHORTCUT_WIDTH, y * SHORTCUT_HEIGHT, SHORTCUT_WIDTH, SHORTCUT_HEIGHT);
- _linkUpdate(pbtnLink, ciTabIndex, ciLinkIndex, sText, sFilePath, sFileParams);
- // context menu
- pbtnLink->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(pbtnLink, SIGNAL(customContextMenuRequested(const QPoint &)),
- SLOT (mnuLink_OnShow(const QPoint &)));
- // clicked()
- _m_smapLinks.setMapping(pbtnLink, pbtnLink);
- connect(pbtnLink, SIGNAL(clicked()),
- &_m_smapLinks, SLOT(map()));
- }
- }
- }
- }
- //------------------------------------------------------------------------------
- void
- CMain::_linkUpdate(
- CLinkButton *a_pbtnLink,
- cint &a_tabIndex,
- cint &a_linkIndex,
- cQString &a_text,
- cQString &a_filePath,
- cQString &a_fileParams
- )
- {
- xTEST_PTR(a_pbtnLink);
- xTEST_LESS(- 1, a_tabIndex);
- xTEST_LESS(- 1, a_linkIndex);
- // a_filePath - n/a
- // a_fileParams - n/a
- a_pbtnLink->setParent( _m_tabLinks->widget(a_tabIndex) );
- a_pbtnLink->setAutoRaise(true);
- a_pbtnLink->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- a_pbtnLink->setVisible(true);
- a_pbtnLink->setTabIndex(a_tabIndex);
- a_pbtnLink->setLinkIndex(a_linkIndex);
- // icon
- {
- QIcon icoIcon;
- if (true == a_filePath.isEmpty()) {
- xNA;
- } else {
- QFileInfo fiInfo(a_filePath);
- icoIcon = QFileIconProvider().icon(fiInfo);
- }
- a_pbtnLink->setIconSize(BUTTON_ICON_SIZE);
- a_pbtnLink->setIcon(icoIcon);
- }
- a_pbtnLink->setText(a_text);
- a_pbtnLink->setToolTip(a_filePath);
- a_pbtnLink->setFilePath(a_filePath);
- a_pbtnLink->setFileParams(a_fileParams);
- }
- //------------------------------------------------------------------------------
- /*******************************************************************************
- * _m_vtbVolumes
- *
- *******************************************************************************/
- //------------------------------------------------------------------------------
- void
- CMain::btnVolume_OnClicked(
- QWidget *a_ptbtnVolume
- )
- {
- // wrap window
- {
- cint ciTitleHeight = ui.frTitle->geometry().height();
- cint ciTargetHeight = ciTitleHeight;
- setFixedHeight(ciTargetHeight);
- }
- QToolButton *ptbTB = dynamic_cast<QToolButton *>( a_ptbtnVolume );
- xTEST_PTR(ptbTB);
- #if defined(Q_OS_WIN)
- cQString sVolumePath = ptbTB->text() + ":";
- #else
- cQString sVolumePath = ptbTB->text();
- #endif
- qCHECK_DO(!CxVolume( qQS2S(sVolumePath) ).isReady(), return);
- bool bRv = QDesktopServices::openUrl( QString("file:///%1").arg(sVolumePath) );
- xTEST_EQ(true, bRv);
- }
- //------------------------------------------------------------------------------
- bool
- CMain::_volumes_Rebuild(
- volume_buttons_t *a_pvtbVolumes
- )
- {
- xTEST_PTR(a_pvtbVolumes);
- //--------------------------------------------------
- // "My computer" button
- {
- // icon
- {
- QIcon icoVolume = QFileIconProvider().icon( QFileIconProvider::Computer );
- ui.tbtnMyComputer->setIcon(icoVolume);
- }
- // tooltip
- {
- CxSystemInfo info;
- std::tstring_t sToolTip = CxString::format(
- xT("OS: %s (%s)\n")
- xT("Shell: %s\n")
- xT("Host: %s\n")
- xT("User: %s\n")
- xT("Cpu: %s %ld MHz\n")
- xT("Ram: %s"),
- info.formatOsType().c_str(),
- info.formatOsArch().c_str(),
- info.desktopName().c_str(),
- info.hostName().c_str(),
- info.userName().c_str(),
- info.cpuModel().c_str(),
- info.cpuSpeed(),
- CxString::formatBytes( info.ramTotal() ).c_str()
- );
- ui.tbtnMyComputer->setToolTip( qS2QS(sToolTip) );
- }
- }
- //--------------------------------------------------
- // hide volume buttons
- for (int i = 0; i < a_pvtbVolumes->size(); ++ i) {
- a_pvtbVolumes->at(i)->setVisible(false);
- }
- //--------------------------------------------------
- // build volume buttons
- std::vector<std::tstring_t> vsVolumes;
- CxVolume::paths(&vsVolumes);
- // HACK: when mobile (SE) inserted - QVector<T>::at: "index out of range"
- {
- std::csize_t ciVolumesMax = 8;
- if (ciVolumesMax < vsVolumes.size()) {
- vsVolumes.resize(ciVolumesMax);
- }
- }
- for (size_t i = 0; i < vsVolumes.size(); ++ i) {
- // text
- {
- std::tstring_t sCaption = vsVolumes.at(i);
- #if defined(Q_OS_WIN)
- // remove colon and slash
- sCaption.resize(vsVolumes.at(i).size() - std::tstring_t(xT(":\\")).size());
- #endif
- a_pvtbVolumes->at(i)->setText( qS2QS(sCaption) );
- }
- // icon
- {
- QFileIconProvider fipProvider;
- QFileInfo fiInfo( qS2QS(vsVolumes.at(i)) );
- QIcon icoVolume = fipProvider.icon(fiInfo);
- a_pvtbVolumes->at(i)->setIcon(icoVolume);
- }
- // tooltip
- {
- std::tstring_t sLabel;
- ulonglong_t ullFreeBytesAvailable = 0ULL;
- ulonglong_t ullTotalNumberOfBytes = 0ULL;
- ulonglong_t ullTotalNumberOfFreeBytes = 0ULL;
- bool bRv = CxVolume(vsVolumes.at(i)).isReady();
- if (false == bRv) {
- sLabel = xT("");
- ullFreeBytesAvailable = 0ULL;
- ullTotalNumberOfBytes = 0ULL;
- ullTotalNumberOfFreeBytes = 0ULL;
- } else {
- sLabel = CxVolume(vsVolumes.at(i)).label();
- CxVolume::space(vsVolumes.at(i),
- &ullFreeBytesAvailable,
- &ullTotalNumberOfBytes,
- &ullTotalNumberOfFreeBytes);
- }
- std::tstring_t sToolTip = CxString::format(
- xT("Label: %s\n")
- xT("Total: %s\n")
- xT("Free: %s"),
- sLabel.c_str(),
- CxString::formatBytes(ullTotalNumberOfBytes).c_str(),
- CxString::formatBytes(ullTotalNumberOfFreeBytes).c_str()
- );
- a_pvtbVolumes->at(i)->setToolTip( qS2QS(sToolTip) );
- }
- // visible
- {
- a_pvtbVolumes->at(i)->setVisible(true);
- }
- }
- return true;
- }
- //------------------------------------------------------------------------------
- /*******************************************************************************
- * menu Dirs
- *
- *******************************************************************************/
- //------------------------------------------------------------------------------
- void
- CMain::_menuDirs_Create(
- QMenu *a_pmnuMenu,
- QObject *a_parent
- )
- {
- QString sControlPanelPath;
- // get "control.exe" file path (for getting icon)
- {
- #if defined(Q_OS_WIN)
- std::tstring_t sRv;
- sRv.resize(xPATH_MAX);
- UINT uiRes = ::GetSystemDirectory(&sRv.at(0), sRv.size());
- sRv.resize(uiRes);
- sRv += CxConst::xSLASH;
- sRv += xT("control.exe");
- sControlPanelPath = qS2QS(sRv);
- #else
- #pragma message "TODO: get 'control.exe' file path (for getting icon)"
- #endif
- }
- // get "My documents" dir path (for getting icon)
- QString sMyDocumentsPath;
- sMyDocumentsPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
- // icons
- QIcon icoHome = QProxyStyle().standardIcon(QStyle::SP_DirHomeIcon);
- QIcon icoDesktop = QFileIconProvider().icon( QFileIconProvider::Desktop );
- QIcon icoProgramFiles = QFileIconProvider().icon( QFileIconProvider::Folder );
- QIcon icoMyDocuments = QFileIconProvider().icon( QFileInfo(sMyDocumentsPath) );
- QIcon icoMyComputer = QFileIconProvider().icon( QFileIconProvider::Computer );
- QIcon icoControlPanel = QFileIconProvider().icon( QFileInfo(sControlPanelPath) );
- QIcon icoOsCore = QFileIconProvider().icon( QFileIconProvider::Folder );
- #if defined(Q_OS_WIN)
- QIcon icoAutorun = QFileIconProvider().icon( QFileIconProvider::Folder );
- QIcon icoSendTo = QFileIconProvider().icon( QFileIconProvider::Folder );
- #endif
- QIcon icoTemp = QFileIconProvider().icon( QFileIconProvider::Folder );
- QIcon icoNetwork = QFileIconProvider().icon( QFileIconProvider::Network );
- QIcon icoTrash = QFileIconProvider().icon( QFileIconProvider::Trashcan );
- // actions
- QAction *acHome = new QAction(icoHome, tr("Home"), a_parent);
- connect(acHome, &QAction::triggered,
- this, &CMain::mnuDirs_OnHome);
- QAction *acDesktop = new QAction(icoDesktop, tr("Desktop"), a_parent);
- connect(acDesktop, &QAction::triggered,
- this, &CMain::mnuDirs_OnDesktop);
- QAction *acProgramFiles = new QAction(icoProgramFiles, tr("Program files"), a_parent);
- connect(acProgramFiles, &QAction::triggered,
- this, &CMain::mnuDirs_OnProgramFiles);
- QAction *acMyDocuments = new QAction(icoMyDocuments, tr("My documents"), a_parent);
- connect(acMyDocuments, &QAction::triggered,
- this, &CMain::mnuDirs_OnMyDocuments);
- QAction *acMyComputer = new QAction(icoMyComputer, tr("My computer"), a_parent);
- connect(acMyComputer, &QAction::triggered,
- this, &CMain::mnuDirs_OnMyComputer);
- QAction *acControlPanel = new QAction(icoControlPanel, tr("Control panel"), a_parent);
- connect(acControlPanel, &QAction::triggered,
- this, &CMain::mnuDirs_OnControlPanel);
- QAction *acOsCore = new QAction(icoOsCore, tr("OS core"), a_parent);
- connect(acOsCore, &QAction::triggered,
- this, &CMain::mnuDirs_OnOsCore);
- #if defined(Q_OS_WIN)
- QAction *acAutorun = new QAction(icoAutorun, tr("Autorun"), a_parent);
- connect(acAutorun, &QAction::triggered,
- this, &CMain::mnuDirs_OnAutorun);
- QAction *acSendTo = new QAction(icoSendTo, tr("Sent to"), a_parent);
- connect(acSendTo, &QAction::triggered,
- this, &CMain::mnuDirs_OnSendTo);
- #endif
- QAction *acTemp = new QAction(icoTemp, tr("Temp"), a_parent);
- connect(acTemp, &QAction::triggered,
- this, &CMain::mnuDirs_OnTemp);
- QAction *acNetwork = new QAction(icoNetwork, tr("Network"), a_parent);
- connect(acNetwork, &QAction::triggered,
- this, &CMain::mnuDirs_OnNetwork);
- QAction *acTrash = new QAction(icoTrash, tr("Trash"), a_parent);
- connect(acTrash, &QAction::triggered,
- this, &CMain::mnuDirs_OnTrash);
- // add actions
- a_pmnuMenu->addAction(acHome);
- a_pmnuMenu->addAction(acDesktop);
- a_pmnuMenu->addAction(acProgramFiles);
- a_pmnuMenu->addAction(acMyDocuments);
- a_pmnuMenu->addAction(acMyComputer);
- a_pmnuMenu->addAction(acControlPanel);
- a_pmnuMenu->addAction(acOsCore);
- #if defined(Q_OS_WIN)
- a_pmnuMenu->addAction(acAutorun);
- a_pmnuMenu->addAction(acSendTo);
- #endif
- a_pmnuMenu->addAction(acTemp);
- a_pmnuMenu->addAction(acNetwork);
- a_pmnuMenu->addAction(acTrash);
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnHome() {
- cQString csDir = QString("file:///%1")
- .arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
- bool bRv = QDesktopServices::openUrl(csDir);
- xTEST_EQ(true, bRv);
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnDesktop() {
- cQString csDir = QString("file:///%1")
- .arg(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
- bool bRv = QDesktopServices::openUrl(csDir);
- xTEST_EQ(true, bRv);
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnProgramFiles() {
- QString sDir;
- {
- #if defined(Q_OS_WIN)
- LPITEMIDLIST pidl = {0};
- ::SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES , &pidl);
- tchar_t szBuff[MAX_PATH + 1] = {0};
- ::SHGetPathFromIDList(pidl, szBuff);
- sDir = QString("file:///") + qS2QS(szBuff);
- #else
- sDir = QString("file:///%1").arg(SPECIAL_DIR_PROGRAM_FILES);
- #endif
- }
- bool bRv = QDesktopServices::openUrl( QUrl(sDir) );
- xTEST_EQ(true, bRv);
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnMyDocuments() {
- cQString csDir = QString("file:///%1")
- .arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
- bool bRv = QDesktopServices::openUrl(csDir);
- xTEST_EQ(true, bRv);
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnMyComputer() {
- #if defined(Q_OS_WIN)
- LPITEMIDLIST lst = {0};
- SHELLEXECUTEINFO se = {0};
- ::SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &lst);
- se.cbSize = sizeof(se);
- se.fMask = SEE_MASK_IDLIST;
- se.hwnd = NULL;
- se.lpVerb = xT("open");
- se.nShow = SW_SHOW;
- se.lpIDList = lst;
- ::ShellExecuteEx(&se);
- (void)::CoTaskMemFree(lst);
- #else
- cQString csDir = QString("file:///%1").arg(QDir::rootPath());
- bool bRv = QDesktopServices::openUrl( QUrl(csDir) );
- xTEST_EQ(true, bRv);
- #endif
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnControlPanel() {
- #if defined(Q_OS_WIN)
- LPITEMIDLIST lst = {0};
- SHELLEXECUTEINFO se = {0};
- ::SHGetSpecialFolderLocation(NULL, CSIDL_CONTROLS, &lst);
- se.cbSize = sizeof(se);
- se.fMask = SEE_MASK_IDLIST;
- se.hwnd = NULL;
- se.lpVerb = xT("open");
- se.nShow = SW_SHOW;
- se.lpIDList = lst;
- ::ShellExecuteEx(&se);
- (void)::CoTaskMemFree(lst);
- #else
- QString sFile;
- cQString csDesktop = QString().fromStdString( CxSystemInfo().desktopName() );
- if ("gnome" == csDesktop) {
- sFile = "/usr/bin/gnome-control-center";
- }
- else if ("kde" == csDesktop || "kde-plasma" == csDesktop) {
- sFile = "/usr/bin/systemsettings";
- }
- else if ("xfce" == csDesktop) {
- sFile = "/usr/bin/xfce4-settings-manager";
- }
- else {
- sFile = "";
- }
- qDebug() << qDEBUG_VAR(csDesktop);
- cQString dir = QString("file:///%1").arg(sFile);
- bool bRv = QDesktopServices::openUrl( QUrl(dir) );
- xTEST_EQ(true, bRv);
- #endif
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnOsCore() {
- QString sDir;
- {
- #if defined(Q_OS_WIN)
- LPITEMIDLIST pidl = {0};
- ::SHGetSpecialFolderLocation(NULL, CSIDL_WINDOWS, &pidl);
- tchar_t szBuff[MAX_PATH + 1] = {0};
- ::SHGetPathFromIDList(pidl, szBuff);
- sDir = QString("file:///%1") + qS2QS(szBuff);
- #else
- sDir = QString("file:///%1").arg(SPECIAL_DIR_OS_CORE);
- #endif
- }
- bool bRv = QDesktopServices::openUrl( QUrl(sDir) );
- xTEST_EQ(true, bRv);
- }
- //------------------------------------------------------------------------------
- #if defined(Q_OS_WIN)
- void
- CMain::mnuDirs_OnAutorun() {
- QString sDir;
- {
- #if defined(Q_OS_WIN)
- LPITEMIDLIST pidl = {0};
- ::SHGetSpecialFolderLocation(NULL, CSIDL_STARTUP, &pidl);
- tchar_t szBuff[MAX_PATH + 1] = {0};
- ::SHGetPathFromIDList(pidl, szBuff);
- sDir = QString("file:///%1") + qS2QS(szBuff);
- #else
- #pragma message "TODO: Unix part"
- #endif
- }
- bool bRv = QDesktopServices::openUrl( QUrl(sDir) );
- xTEST_EQ(true, bRv);
- }
- #endif
- //------------------------------------------------------------------------------
- #if defined(Q_OS_WIN)
- void
- CMain::mnuDirs_OnSendTo() {
- QString sDir;
- {
- LPITEMIDLIST pidl = {0};
- ::SHGetSpecialFolderLocation(NULL, CSIDL_SENDTO, &pidl);
- tchar_t szBuff[MAX_PATH + 1] = {0};
- ::SHGetPathFromIDList(pidl, szBuff);
- sDir = QString("file:///%1") + qS2QS(szBuff);
- }
- bool bRv = QDesktopServices::openUrl( QUrl(sDir) );
- xTEST_EQ(true, bRv);
- }
- #endif
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnTemp() {
- cQString csDir = QString("file:///%1")
- .arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
- bool bRv = QDesktopServices::openUrl( QUrl(csDir) );
- xTEST_EQ(true, bRv);
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnNetwork() {
- #if defined(Q_OS_WIN)
- LPITEMIDLIST lst = {0};
- SHELLEXECUTEINFO se = {0};
- ::SHGetSpecialFolderLocation(NULL, CSIDL_NETWORK, &lst);
- se.cbSize = sizeof(se);
- se.fMask = SEE_MASK_IDLIST;
- se.hwnd = NULL;
- se.lpVerb = xT("open");
- se.nShow = SW_SHOW;
- se.lpIDList = lst;
- ::ShellExecuteEx(&se);
- (void)::CoTaskMemFree(lst);
- #else
- QString sFile;
- cQString csDesktop = QString().fromStdString( CxSystemInfo().desktopName() );
- if ("gnome" == csDesktop) {
- sFile = "/usr/bin/gnome-network-properties";
- }
- else if ("kde" == csDesktop || "kde-plasma" == csDesktop) {
- #pragma message "TODO: mnuDirs_OnNetwork"
- sFile = "/usr/bin/knetworkmanager";
- }
- else if ("xfce" == csDesktop) {
- #pragma message "TODO: mnuDirs_OnNetwork"
- sFile = "";
- }
- else {
- sFile = "";
- }
- QString sDir = QString("file:///%1").arg(sFile);
- bool bRv = QDesktopServices::openUrl( QUrl(sDir) );
- xTEST_EQ(true, bRv);
- #endif
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuDirs_OnTrash() {
- #if defined(Q_OS_WIN)
- LPITEMIDLIST lst = {0};
- SHELLEXECUTEINFO se = {0};
- ::SHGetSpecialFolderLocation(NULL, CSIDL_BITBUCKET, &lst);
- se.cbSize = sizeof(se);
- se.fMask = SEE_MASK_IDLIST;
- se.hwnd = NULL;
- se.lpVerb = xT("open");
- se.nShow = SW_SHOW;
- se.lpIDList = lst;
- ::ShellExecuteEx(&se);
- (void)::CoTaskMemFree(lst);
- #else
- cQString csDir = QString("file:///%1/%2")
- .arg(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).toVector().at(0))
- .arg(SPECIAL_RELATIVE_DIR_TRASH);
- bool bRv = QDesktopServices::openUrl( QUrl(csDir) );
- xTEST_EQ(true, bRv);
- #endif
- }
- //------------------------------------------------------------------------------
- /*******************************************************************************
- * _m_tabLinks
- *
- *******************************************************************************/
- //------------------------------------------------------------------------------
- void
- CMain::mnuLinks_OnShow(
- const QPoint &a_point
- )
- {
- _m_bIsAllowWrap = false;
- qCHECK_DO(true == a_point.isNull(), return);
- QMenu mnuLinks(this);
- // actions
- QAction *acTabAdd = new QAction(tr("Tab add"), this);
- connect(acTabAdd, &QAction::triggered,
- this, &CMain::mnuLinks_OnTabAdd);
- QAction *acTabRemove = new QAction(tr("Tab remove"), this);
- connect(acTabRemove, &QAction::triggered,
- this, &CMain::mnuLinks_OnTabRemove);
- QAction *acTabRename = new QAction(tr("Tab rename"), this);
- connect(acTabRename, &QAction::triggered,
- this, &CMain::mnuLinks_OnTabRename);
- // add actions
- mnuLinks.addAction(acTabAdd);
- mnuLinks.addAction(acTabRemove);
- mnuLinks.addAction(acTabRename);
- mnuLinks.exec( _m_tabLinks->mapToGlobal(a_point) );
- _m_bIsAllowWrap = true;
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuLinks_OnTabAdd() {
- // Get table name
- QString sTabName;
- {
- QInputDialog idlgInputDialog(this);
- cint ciRv = idlgInputDialog.exec();
- switch (ciRv) {
- case QDialog::Rejected:
- return;
- break;
- case QDialog::Accepted:
- qCHECK_DO(true == idlgInputDialog.textValue().isEmpty(), return);
- sTabName = idlgInputDialog.textValue();
- break;
- default:
- xTEST_FAIL;
- break;
- }
- }
- // to UI
- {
- _tabPageAddEmpty(sTabName);
- _tabPageShow(sTabName);
- }
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuLinks_OnTabRemove() {
- // ask for removing
- {
- cQString csText = tr("Remove the tab and all its content?");
- cint ciRv = QMessageBox::question(this, qApp->applicationName(), csText,
- QMessageBox::Ok | QMessageBox::No);
- switch (ciRv) {
- case QMessageBox::Ok:
- xNA;
- break;
- default:
- case QMessageBox::No:
- return;
- break;
- }
- }
- cQString csTabName = _m_tabLinks->tabText( _m_tabLinks->currentIndex() );
- // to DB
- {
- // from t_tabs
- {
- QSqlQuery qryDelete(_m_dbDatabase);
- cQString csSql = \
- "DELETE FROM t_tabs WHERE f_name=:p_tab_name;";
- bool bRv = qryDelete.prepare(csSql);
- qCHECK_REF(bRv, qryDelete)
- qryDelete.bindValue(":p_tab_name", csTabName);
- bRv = qryDelete.exec();
- qCHECK_REF(bRv, qryDelete);
- }
- // from t_main
- {
- QSqlQuery qryDelete(_m_dbDatabase);
- cQString csSql = \
- "DELETE FROM t_main WHERE f_tab_index=:p_tab_index";
- bool bRv = qryDelete.prepare(csSql);
- qCHECK_REF(bRv, qryDelete)
- qryDelete.bindValue(":p_tab_index", _m_tabLinks->currentIndex());
- bRv = qryDelete.exec();
- qCHECK_REF(bRv, qryDelete);
- }
- }
- // to UI
- {
- _m_tabLinks->removeTab( _m_tabLinks->currentIndex() );
- }
- }
- //------------------------------------------------------------------------------
- void
- CMain::mnuLinks_On…
Large files files are truncated, but you can click here to view the full file