From 75cb0218b17cc58ed6ae2f0b4f902b893a19a12c Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Sun, 23 Apr 2023 16:27:45 +0800 Subject: [PATCH] Remove some compilation warnings. --- frontend/mainwindow.cpp | 53 ------------------- frontend/mainwindow.h | 5 -- frontend/model/search-result-model.cpp | 19 ------- frontend/model/search-result-model.h | 2 - .../appdata/application-property-helper.cpp | 3 ++ libsearch/file-utils.cpp | 11 ++-- libsearch/file-utils.h | 2 +- libsearch/index/file-search-plugin.cpp | 2 + libsearch/index/search-manager.cpp | 4 +- libsearch/pluginmanage/plugin-info.h | 6 +-- .../search-result-property-info.cpp | 2 + search-ukcc-plugin/search.cpp | 2 +- .../app-db-manager.cpp | 34 ++++++------ ukui-search-app-data-service/app-db-manager.h | 4 +- .../convert-winid-to-desktop.cpp | 8 +-- .../convert-winid-to-desktop.h | 1 - 16 files changed, 43 insertions(+), 115 deletions(-) diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index c4ba6f5..8940f3b 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -266,59 +266,6 @@ void MainWindow::ScreenGeometryChanged(QRect rect) { } } -/** - * @brief MainWindow::moveToPanel 将主界面移动到任务栏旁边(跟随任务栏位置) - */ -void MainWindow::moveToPanel() { - QRect availableGeometry = qApp->primaryScreen()->availableGeometry(); - QRect screenGeometry = qApp->primaryScreen()->geometry(); - - QDBusInterface primaryScreenInterface("org.ukui.SettingsDaemon", - "/org/ukui/SettingsDaemon/wayland", - "org.ukui.SettingsDaemon.wayland", - QDBusConnection::sessionBus()); - if(QDBusReply(primaryScreenInterface.call("x")).isValid()) { - QDBusReply x = primaryScreenInterface.call("x"); - QDBusReply y = primaryScreenInterface.call("y"); - QDBusReply width = primaryScreenInterface.call("width"); - QDBusReply height = primaryScreenInterface.call("height"); - screenGeometry.setX(x); - screenGeometry.setY(y); - screenGeometry.setWidth(width); - screenGeometry.setHeight(height); - availableGeometry.setX(x); - availableGeometry.setY(y); - availableGeometry.setWidth(width); - availableGeometry.setHeight(height); - } - - QDesktopWidget * desktopWidget = QApplication::desktop(); - QRect screenMainRect = desktopWidget->screenGeometry(0);//获取设备屏幕大小 - - QDBusInterface interface("com.ukui.panel.desktop", - "/", - "com.ukui.panel.desktop", - QDBusConnection::sessionBus()); - - int position = QDBusReply(interface.call("GetPanelPosition", "position")); - int height = QDBusReply(interface.call("GetPanelSize", "height")); - int d = 8; //窗口边沿到任务栏距离 - - if(position == 0) { - //任务栏在下侧 - this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenGeometry.y() + screenGeometry.height() - this->height() - height - d); - } else if(position == 1) { - //任务栏在上侧 - this->move(availableGeometry.x() + availableGeometry.width() - this->width() - d, screenGeometry.y() + height + d); - } else if(position == 2) { - //任务栏在左侧 - this->move(screenGeometry.x() + height + d, screenGeometry.y() + screenGeometry.height() - this->height() - d); - } else if(position == 3) { - //任务栏在右侧 - this->move(screenGeometry.x() + screenGeometry.width() - this->width() - height - d, screenGeometry.y() + screenGeometry.height() - this->height() - d); - } -} - /** * @brief MainWindow::centerToScreen 使窗口显示在屏幕中间 * @param widget diff --git a/frontend/mainwindow.h b/frontend/mainwindow.h index cb5ed84..378c1d2 100644 --- a/frontend/mainwindow.h +++ b/frontend/mainwindow.h @@ -67,11 +67,6 @@ class MainWindow : public QMainWindow { public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); - /** - * @brief Load the main window - * The position which mainwindow shows follow the ukui-panel. - */ - void moveToPanel(); // The position which mainwindow shows in the center of screen where the cursor in. void centerToScreen(QWidget* widget); diff --git a/frontend/model/search-result-model.cpp b/frontend/model/search-result-model.cpp index 51a3484..9204d8a 100644 --- a/frontend/model/search-result-model.cpp +++ b/frontend/model/search-result-model.cpp @@ -135,25 +135,6 @@ const bool &SearchResultModel::isExpanded() return m_isExpanded; } -/** - * @brief SearchResultModel::getActions 获取操作列表 - * @param index - * @return - */ -QStringList SearchResultModel::getActions(const QModelIndex &index) -{ - if (m_item->m_result_info_list.length() > index.row() && index.row() >= 0) -// return m_item->m_result_info_list.at(index.row()).actionList; - return QStringList(); -} - -QString SearchResultModel::getKey(const QModelIndex &index) -{ - if (m_item->m_result_info_list.length() > index.row() && index.row() >= 0) -// return m_item->m_result_info_list.at(index.row()).key; - return NULL; -} - void SearchResultModel::refresh() { this->beginResetModel(); diff --git a/frontend/model/search-result-model.h b/frontend/model/search-result-model.h index e8cc153..afc8589 100644 --- a/frontend/model/search-result-model.h +++ b/frontend/model/search-result-model.h @@ -54,8 +54,6 @@ public: const SearchPluginIface::ResultInfo & getInfo(const QModelIndex&); void setExpanded(const bool&); const bool &isExpanded(); - QStringList getActions(const QModelIndex &); - QString getKey(const QModelIndex &); void refresh(); public Q_SLOTS: diff --git a/libsearch/appdata/application-property-helper.cpp b/libsearch/appdata/application-property-helper.cpp index 8a8c238..553dd12 100644 --- a/libsearch/appdata/application-property-helper.cpp +++ b/libsearch/appdata/application-property-helper.cpp @@ -109,6 +109,9 @@ ApplicationPropertyHelper::ApplicationPropertyHelper(ApplicationProperty::Proper case ApplicationProperty::AutoStart: d->m_databaseField = "AUTO_START"; d->m_valueType = QMetaType::Int; + break; + default: + break; } } diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index 04b8dd9..e259d5e 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -781,14 +781,9 @@ QString FileUtils::escapeHtml(const QString &str) return temp; } -QString FileUtils::chineseSubString(const std::string &myStr, int start, int length) +QString FileUtils::chineseSubString(const std::string &myStr, uint start, uint length) { std::string afterSub = ""; - //越界保护 - if(start < 0 || length < 0){ - return " "; - } - QString sub = QString::fromStdString(myStr); QFont ft(QApplication::font().family(),QApplication::font().pointSize()); QFontMetrics fm (ft); @@ -813,7 +808,7 @@ QString FileUtils::chineseSubString(const std::string &myStr, int start, int len } sub = fm.elidedText(sub, Qt::ElideRight, 2*LABEL_MAX_WIDTH); //超过两行则省略 } else { - int newStart = myStr.length()-length; //更新截取位置 + uint newStart = myStr.length()-length; //更新截取位置 afterSub = myStr.substr(newStart, length); sub=QString::fromStdString(afterSub); @@ -850,7 +845,7 @@ bool FileUtils::isOpenXMLFileEncrypted(const QString &path) return true; } //比较前四位是否为对应值来判断OpenXML类型文件是否加密 - if (encrypt[0] == 0x50 && encrypt[1] == 0x4b && encrypt[2] == 0x03 && encrypt[3] == 0x04) { + if ((encrypt[0] & 0x50) && (encrypt[1] & 0x4b) && (encrypt[2] & 0x03) && (encrypt[3] & 0x04)) { return false; } else { qDebug() << "Encrypt!" << path; diff --git a/libsearch/file-utils.h b/libsearch/file-utils.h index ee6b517..5dac663 100644 --- a/libsearch/file-utils.h +++ b/libsearch/file-utils.h @@ -62,7 +62,7 @@ public: static int openFile(QString &path, bool openInDir = false); static bool copyPath(QString &path); static QString escapeHtml(const QString &str); - static QString chineseSubString(const std::string &myStr,int start,int length); + static QString chineseSubString(const std::string &myStr, uint start, uint length); static QIcon iconFromTheme(const QString &name, const QIcon &iconDefault); static bool isOpenXMLFileEncrypted(const QString &path); /** diff --git a/libsearch/index/file-search-plugin.cpp b/libsearch/index/file-search-plugin.cpp index eba1a9c..c9ac09e 100644 --- a/libsearch/index/file-search-plugin.cpp +++ b/libsearch/index/file-search-plugin.cpp @@ -300,6 +300,7 @@ void DirSearchPlugin::openAction(int actionkey, QString key, int type) break; case 1: FileUtils::openFile(key, true); + break; case 2: FileUtils::copyPath(key); default: @@ -480,6 +481,7 @@ void FileContengSearchPlugin::openAction(int actionkey, QString key, int type) break; case 1: FileUtils::openFile(key, true); + break; case 2: FileUtils::copyPath(key); default: diff --git a/libsearch/index/search-manager.cpp b/libsearch/index/search-manager.cpp index abfd910..fd79511 100644 --- a/libsearch/index/search-manager.cpp +++ b/libsearch/index/search-manager.cpp @@ -417,11 +417,11 @@ int OcrSearch::keywordSearchOcr() { std::vector sKeyWord = ChineseSegmentation::getInstance()->callSegment(m_keyword.toStdString()); //Creat a query std::string words; - for(int i = 0; i < sKeyWord.size(); i++) { + for(size_t i = 0; i < sKeyWord.size(); i++) { words.append(sKeyWord.at(i).word).append(" "); } std::vector v; - for(int i=0; im_displayName = tr("application package name"); d->m_valueType = QMetaType::QString; break; + default: + break; } } diff --git a/search-ukcc-plugin/search.cpp b/search-ukcc-plugin/search.cpp index cdc9a55..5936739 100644 --- a/search-ukcc-plugin/search.cpp +++ b/search-ukcc-plugin/search.cpp @@ -149,7 +149,7 @@ QWidget *Search::pluginUi() } } }); - connect(m_webEngineFrame->mCombox, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { + connect(m_webEngineFrame->mCombox, QOverload::of(&QComboBox::currentIndexChanged), this, [=] { if (m_gsettings && m_gsettings->keys().contains(WEB_ENGINE_KEY)) { m_gsettings->set(WEB_ENGINE_KEY, m_webEngineFrame->mCombox->currentData().toString()); } diff --git a/ukui-search-app-data-service/app-db-manager.cpp b/ukui-search-app-data-service/app-db-manager.cpp index 0476c22..e7003bc 100644 --- a/ukui-search-app-data-service/app-db-manager.cpp +++ b/ukui-search-app-data-service/app-db-manager.cpp @@ -170,7 +170,7 @@ AppDBManager::AppDBManager(QObject *parent) : QThread(parent), m_database(QSqlDa //监控应用进程开启 connect(KWindowSystem::self(), &KWindowSystem::windowAdded, [ = ](WId id) { - KWindowInfo info = KWindowSystem::windowInfo(id, 0, NET::WM2AllProperties); + KWindowInfo info(id, NET::Properties(), NET::WM2AllProperties); if (info.valid()) { QString desktopfp; desktopfp = this->tranPidToDesktopFp(info.pid()); @@ -863,13 +863,15 @@ bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, co ApplicationInfoMap infos; //获取应用在数据库中的favorites标志位 - int previousPos = -1; + uint previousPos = 0; + bool getPrevious(false); cmd = "SELECT FAVORITES FROM APPINFO WHERE DESKTOP_FILE_PATH =:desktopFilePath"; query.prepare(cmd); query.bindValue(":desktopFilePath", desktopFilePath); if (query.exec()) { if (query.next()) { - previousPos = query.value("FAVORITES").toInt(); + previousPos = query.value("FAVORITES").toUInt(); + getPrevious = true; } else { qWarning() << query.lastQuery() << query.lastError(); } @@ -878,18 +880,18 @@ bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, co } //收藏位未改变 - if (previousPos == num) { + if (getPrevious && previousPos == num) { res = false; qWarning() << "favorites state has no changes, I quit!"; return res; } //查询目前favorites最大值 - int maxFavorite = -1; + uint maxFavorite = 0; query.prepare("SELECT max(FAVORITES) as max FROM APPINFO"); if (query.exec()) { if (query.next()) { - maxFavorite = query.value("max").toInt(); + maxFavorite = query.value("max").toUInt(); if (maxFavorite + 1 < num) { qWarning() << QString("Max favorites pos is %0.To be moved to a invalid pos, I quit!!").arg(query.value("max").toInt()); res = false; @@ -934,7 +936,7 @@ bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, co } } else { //直接设置时(要设置的应用未被收藏),查询要设置的favorites标志位是否被占用,占用则将该应用及其之后的应用的favorites标志位后移 - if (!previousPos) { + if (getPrevious && !previousPos) { cmd = QString("SELECT DESKTOP_FILE_PATH FROM APPINFO WHERE FAVORITES = %1").arg(num); if (!query.exec(cmd)) { qWarning() << "Fail to exec:" << cmd << "because:" << query.lastError(); @@ -999,7 +1001,7 @@ bool AppDBManager::handleFavoritesStateUpdate(const QString &desktopFilePath, co return res; } -bool AppDBManager::handleChangeFavoritesPos(const QString &desktopFilePath, const uint pos, const int previousPos, ApplicationInfoMap &updatedInfo) +bool AppDBManager::handleChangeFavoritesPos(const QString &desktopFilePath, const uint pos, const uint previousPos, ApplicationInfoMap &updatedInfo) { if (pos < 1) { qWarning() << "To be moved to a invalid favorites pos , I quit!!"; @@ -1059,13 +1061,15 @@ bool AppDBManager::handleTopStateUpdate(const QString &desktopFilePath, const ui ApplicationInfoMap infos; //获取应用在数据库中的top标志位 - int previousPos = -1; + uint previousPos = 0; + bool getPrevious(false); cmd = "SELECT TOP FROM APPINFO WHERE DESKTOP_FILE_PATH =:desktopFilePath"; query.prepare(cmd); query.bindValue(":desktopFilePath", desktopFilePath); if (query.exec()) { if (query.next()) { - previousPos = query.value("TOP").toInt(); + previousPos = query.value("TOP").toUInt(); + getPrevious = true; } else { qWarning() << query.lastQuery() << query.lastError(); } @@ -1074,18 +1078,18 @@ bool AppDBManager::handleTopStateUpdate(const QString &desktopFilePath, const ui } //top位未改变 - if (previousPos == num) { + if (getPrevious && previousPos == num) { res = false; qWarning() << "Top state has no changes, I quit!"; return res; } //查询目前top最大值 - int maxTop = -1; + uint maxTop = 0; query.prepare("SELECT max(TOP) as max FROM APPINFO"); if (query.exec()) { if (query.next()) { - maxTop = query.value("max").toInt(); + maxTop = query.value("max").toUInt(); if (maxTop + 1 < num) { qWarning() << QString("Max top pos is %0.To be moved to a invalid pos, I quit!!").arg(query.value("max").toInt()); res = false; @@ -1132,7 +1136,7 @@ bool AppDBManager::handleTopStateUpdate(const QString &desktopFilePath, const ui } } else { //直接设置时,查询要设置的top标志位是否被占用,占用则将该应用及其之后的应用的top标志位后移 - if (!previousPos) { + if (getPrevious && !previousPos) { cmd = QString("SELECT DESKTOP_FILE_PATH FROM APPINFO WHERE TOP = %1").arg(num); if (!query.exec(cmd)) { qWarning() << "Fail to exec:" << cmd << "because:" << query.lastError(); @@ -1196,7 +1200,7 @@ bool AppDBManager::handleTopStateUpdate(const QString &desktopFilePath, const ui return res; } -bool AppDBManager::handleChangeTopPos(const QString &desktopFilePath, uint pos, const int previousPos, ApplicationInfoMap &updatedInfo) +bool AppDBManager::handleChangeTopPos(const QString &desktopFilePath, uint pos, const uint previousPos, ApplicationInfoMap &updatedInfo) { if (pos < 1) { qWarning() << "To be moved to a invalid top pos , I quit!!"; diff --git a/ukui-search-app-data-service/app-db-manager.h b/ukui-search-app-data-service/app-db-manager.h index 53772ee..f9bc6ec 100644 --- a/ukui-search-app-data-service/app-db-manager.h +++ b/ukui-search-app-data-service/app-db-manager.h @@ -127,8 +127,8 @@ private: void initFileSystemWatcher(); //处理置顶收藏移动位置 - bool handleChangeFavoritesPos(const QString &desktopFilePath, const uint pos, const int previousPos, ApplicationInfoMap &updatedInfo); - bool handleChangeTopPos(const QString &desktopFilePath, uint pos, const int previousPos, ApplicationInfoMap &updatedInfo); + bool handleChangeFavoritesPos(const QString &desktopFilePath, const uint pos, const uint previousPos, ApplicationInfoMap &updatedInfo); + bool handleChangeTopPos(const QString &desktopFilePath, uint pos, const uint previousPos, ApplicationInfoMap &updatedInfo); private: static QMutex s_mutex; diff --git a/ukui-search-app-data-service/convert-winid-to-desktop.cpp b/ukui-search-app-data-service/convert-winid-to-desktop.cpp index eaa32c3..cf5a614 100755 --- a/ukui-search-app-data-service/convert-winid-to-desktop.cpp +++ b/ukui-search-app-data-service/convert-winid-to-desktop.cpp @@ -22,6 +22,8 @@ #include #include "convert-winid-to-desktop.h" +static const char* GET_DESKTOP_EXEC_NAME_MAIN = "cat %s | awk '{if($1~\"Exec=\")if($2~\"\%\"){print $1} else print}' | cut -d '=' -f 2"; + ConvertWinidToDesktop::ConvertWinidToDesktop(QObject *parent) : QObject(parent) { } @@ -176,7 +178,7 @@ QString ConvertWinidToDesktop::compareCmdExec(QFileInfoList list) if (!fileInfo.filePath().endsWith(".desktop")) { continue; } - cmd.sprintf(GET_DESKTOP_EXEC_NAME_MAIN, fileInfo.filePath().toStdString().data()); + cmd.asprintf(GET_DESKTOP_EXEC_NAME_MAIN, fileInfo.filePath().toStdString().data()); QString desktopFileExeName = getDesktopFileName(cmd).remove("\n"); if (desktopFileExeName.isEmpty()) { @@ -219,7 +221,7 @@ QString ConvertWinidToDesktop::compareCmdName(QFileInfoList list) if (!fileInfo.filePath().endsWith(".desktop")) { continue; } - cmd.sprintf(GET_DESKTOP_EXEC_NAME_MAIN, fileInfo.filePath().toStdString().data()); + cmd.asprintf(GET_DESKTOP_EXEC_NAME_MAIN, fileInfo.filePath().toStdString().data()); QString desktopFileExeName = getDesktopFileName(cmd).remove("\n"); if (desktopFileExeName.isEmpty()) { @@ -265,7 +267,7 @@ QString ConvertWinidToDesktop::containsName(QFileInfoList list) continue; } - cmd.sprintf(GET_DESKTOP_EXEC_NAME_MAIN, fileInfo.filePath().toStdString().data()); + cmd.asprintf(GET_DESKTOP_EXEC_NAME_MAIN, fileInfo.filePath().toStdString().data()); QString desktopFileExeName = getDesktopFileName(cmd).remove("\n"); pathDesktopName = pathDesktopName.mid(pathDesktopName.lastIndexOf("/") + 1); diff --git a/ukui-search-app-data-service/convert-winid-to-desktop.h b/ukui-search-app-data-service/convert-winid-to-desktop.h index 38c30ca..383d6a4 100755 --- a/ukui-search-app-data-service/convert-winid-to-desktop.h +++ b/ukui-search-app-data-service/convert-winid-to-desktop.h @@ -31,7 +31,6 @@ #define PEONY_HOME "/usr/share/applications/peony-home.desktop" #define PEONY_MAIN "/usr/share/applications/peony.desktop" -#define GET_DESKTOP_EXEC_NAME_MAIN "cat %s | awk '{if($1~\"Exec=\")if($2~\"\%\"){print $1} else print}' | cut -d '=' -f 2" #define ANDROID_FILE_PATH "/.local/share/applications/" #define ANDROID_APP_CURRENT "/.local/share/applications/." #define ANDROID_APP_UPER "/.local/share/applications/.."