| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#include <DVtableHook> |
| 22 |
#define protected public |
| 23 |
#include <DApplication> |
| 24 |
#undef protected |
| 25 |
|
| 26 |
#include "application.h" |
| 27 |
#include "mainwindow.h" |
| 28 |
#include "imageengine/imageengineapi.h" |
| 29 |
#include "accessibledefine.h" |
| 30 |
#include "accessible.h" |
| 31 |
|
| 32 |
#include <DMainWindow> |
| 33 |
#include <DWidgetUtil> |
| 34 |
#include <DApplicationSettings> |
| 35 |
#include <DLog> |
| 36 |
#include <DStandardPaths> |
| 37 |
|
| 38 |
#include <QMessageBox> |
| 39 |
#include <QStandardPaths> |
| 40 |
#include <QSettings> |
| 41 |
#include <QThread> |
| 42 |
|
| 43 |
#include "imagedataservice.h" |
| 44 |
#include "baseutils.h" |
| 45 |
|
| 46 |
DWIDGET_USE_NAMESPACE |
| 47 |
DCORE_USE_NAMESPACE |
| 48 |
|
| 49 |
int main(int argc, char *argv[]) |
| 50 |
{ |
| 51 |
//非wayland平台需要添加xcb |
| 52 |
if (Application::isWaylandPlatform()) { |
| 53 |
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "kwayland-shell"); //add wayland parameter |
| 54 |
} |
| 55 |
|
| 56 |
//for qt5platform-plugins load DPlatformIntegration or DPlatformIntegrationParent |
| 57 |
if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin")) { |
| 58 |
setenv("XDG_CURRENT_DESKTOP", "Deepin", 1); |
| 59 |
} |
| 60 |
|
| 61 |
#if (DTK_VERSION < DTK_VERSION_CHECK(5, 4, 0, 0)) |
| 62 |
QScopedPointer<DApplication> dAppNew(new DApplication(argc, argv)); |
| 63 |
#else |
| 64 |
DApplication *dAppNew = DApplication::globalApplication(argc, argv); |
| 65 |
#endif |
| 66 |
|
| 67 |
#ifdef ENABLE_ACCESSIBILITY |
| 68 |
#endif |
| 69 |
setlocale(LC_NUMERIC, "C"); |
| 70 |
dAppNew->setAttribute(Qt::AA_UseHighDpiPixmaps); |
| 71 |
QAccessible::installFactory(accessibleFactory); |
| 72 |
dAppNew->setOrganizationName("deepin"); |
| 73 |
dAppNew->setApplicationName("deepin-album"); |
| 74 |
dAppNew->loadTranslator(QList<QLocale>() << QLocale::system()); |
| 75 |
|
| 76 |
Application::getApp()->setApp(dAppNew); |
| 77 |
|
| 78 |
qputenv("DTK_USE_SEMAPHORE_SINGLEINSTANCE", "1"); |
| 79 |
|
| 80 |
QCommandLineParser parser; |
| 81 |
parser.process(*dAppNew); |
| 82 |
|
| 83 |
QStringList urls; |
| 84 |
QStringList arguments = parser.positionalArguments(); |
| 85 |
QString filepath = ""; |
| 86 |
bool bneedexit = true; |
| 87 |
for (const QString &path : arguments) { |
| 88 |
filepath = utils::base::UrlInfo(path).toLocalFile(); |
| 89 |
|
| 90 |
QFileInfo info(filepath); |
| 91 |
QString str = info.suffix().toLower(); |
| 92 |
qDebug() << __FUNCTION__ << "---" << str; |
| 93 |
if (utils::image::supportedImageFormats().contains(str, Qt::CaseInsensitive) || |
| 94 |
utils::base::isVideo(filepath)) { //增加对视频格式的支持 |
| 95 |
bneedexit = false; |
| 96 |
break; |
| 97 |
} else if (str.isEmpty()) { |
| 98 |
bneedexit = false; |
| 99 |
break; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
if ("" != filepath && bneedexit) { |
| 104 |
exit(0); |
| 105 |
} |
| 106 |
|
| 107 |
if (!bneedexit) { |
| 108 |
if (bfirstopen) { |
| 109 |
bfirstandviewimage = true; |
| 110 |
} |
| 111 |
} |
| 112 |
//save theme |
| 113 |
DApplicationSettings savetheme; |
| 114 |
|
| 115 |
DLogManager::registerConsoleAppender(); |
| 116 |
DLogManager::registerFileAppender(); |
| 117 |
if (!DGuiApplicationHelper::instance()->setSingleInstance(dAppNew->applicationName(), DGuiApplicationHelper::UserScope)) { |
| 118 |
exit(0); |
| 119 |
} |
| 120 |
|
| 121 |
// LMH0420判断是否相同进程启动 |
| 122 |
if (dApp->isRunning()) { |
| 123 |
return 0; |
| 124 |
} |
| 125 |
|
| 126 |
QString userConfigPath = DStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) |
| 127 |
+ "/config.conf"; |
| 128 |
QSettings *settings = new QSettings(userConfigPath, QSettings::IniFormat); |
| 129 |
const QByteArray geometry = settings->value("album-geometry").toByteArray(); |
| 130 |
int num = settings->value("album-zoomratio").toInt(); |
| 131 |
settings->deleteLater(); |
| 132 |
settings = nullptr; |
| 133 |
QRect restoredFrameGeometry; |
| 134 |
if (!geometry.isEmpty()) { |
| 135 |
QDataStream stream(geometry); |
| 136 |
stream.setVersion(QDataStream::Qt_4_0); |
| 137 |
|
| 138 |
quint32 storedMagicNumber; |
| 139 |
stream >> storedMagicNumber; |
| 140 |
|
| 141 |
quint16 majorVersion = 0; |
| 142 |
quint16 minorVersion = 0; |
| 143 |
|
| 144 |
stream >> majorVersion >> minorVersion; |
| 145 |
QRect restoredNormalGeometry; |
| 146 |
qint32 restoredScreenNumber; |
| 147 |
quint8 maximized; |
| 148 |
quint8 fullScreen; |
| 149 |
|
| 150 |
stream >> restoredFrameGeometry |
| 151 |
>> restoredNormalGeometry |
| 152 |
>> restoredScreenNumber |
| 153 |
>> maximized |
| 154 |
>> fullScreen; |
| 155 |
} |
| 156 |
//计算当前一屏照片数量 |
| 157 |
QMap<int, int> picSize; |
| 158 |
picSize.insert(0, 80); |
| 159 |
picSize.insert(1, 90); |
| 160 |
picSize.insert(2, 100); |
| 161 |
picSize.insert(3, 110); |
| 162 |
picSize.insert(4, 120); |
| 163 |
picSize.insert(5, 130); |
| 164 |
picSize.insert(6, 140); |
| 165 |
picSize.insert(7, 150); |
| 166 |
picSize.insert(8, 160); |
| 167 |
picSize.insert(9, 170); |
| 168 |
if (num < 0 || num > 9) { |
| 169 |
num = 4; |
| 170 |
} |
| 171 |
int picsize = picSize.value(num); |
| 172 |
int number = ((restoredFrameGeometry.width() - 50) * (restoredFrameGeometry.height() - 50)) / (picsize * picsize); |
| 173 |
|
| 174 |
DBManager::instance(); |
| 175 |
ImageDataService::instance(); |
| 176 |
ImageEngineApi::instance(dAppNew); |
| 177 |
// 加载第一屏图片 |
| 178 |
qDebug() << "------" << __FUNCTION__ << "" << QThread::currentThreadId(); |
| 179 |
ImageEngineApi::instance()->loadFirstPageThumbnails(number); |
| 180 |
auto &w = MainWindow::instance(); //修改为从单例获取 |
| 181 |
dApp->setMainWindow(&w); |
| 182 |
w.show(); |
| 183 |
Dtk::Widget::moveToCenter(&w); |
| 184 |
w.startMonitor(); |
| 185 |
|
| 186 |
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 5, 0, 0)) |
| 187 |
dAppNew->ignoreVirtualKeyboard(&w); //禁止虚拟键盘顶起主界面标题栏(DTK5.5有效) |
| 188 |
#endif |
| 189 |
|
| 190 |
if (bneedexit) |
| 191 |
bfirstopen = false; |
| 192 |
|
| 193 |
//警告:这个函数只会将&DApplication::handleQuitAction的地址替换为&MainWindow::closeFromMenu |
| 194 |
// 并不会将dAppNew.get()和&w两个实体变量绑定上去 |
| 195 |
// 因为C++只会为同一个函数生成一份拷贝,实现这个函数的人明显以为每个实体变量都会拥有单独的函数拷贝 |
| 196 |
Dtk::Core::DVtableHook::overrideVfptrFun(dAppNew, &DApplication::handleQuitAction, |
| 197 |
&w, &MainWindow::closeFromMenu); |
| 198 |
|
| 199 |
return dAppNew->exec(); |
| 200 |
} |