Advertisement
Guest User

srcmaincpp

a guest
Jun 4th, 2020
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.27 KB | None | 0 0
  1. diff --git a/src/main.cpp b/src/main.cpp
  2. index 888e6cfa4..e556e56e9 100644
  3. --- a/src/main.cpp
  4. +++ b/src/main.cpp
  5. @@ -40,175 +40,169 @@
  6. using namespace Otter;
  7.  
  8. #if !defined(Q_OS_WIN32)
  9. -void otterMessageHander(QtMsgType type, const QMessageLogContext &context, const QString &message)
  10. -{
  11. - if (message.trimmed().startsWith(QLatin1String("OpenType support missing")) || message.startsWith(QLatin1String("libpng warning: iCCP:")) || message.startsWith(QLatin1String("OpenType support missing for script")) || message.startsWith(QLatin1String("QCoreApplication::postEvent: Unexpected null receiver")) || message.startsWith(QLatin1String("QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once")) || message.startsWith(QLatin1String("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread")) || message.startsWith(QLatin1String("QFSFileEngine::open")) || message.contains(QLatin1String("::_q_startOperation was called more than once")))
  12. - {
  13. - return;
  14. - }
  15. -
  16. - fputs(qFormatLogMessage(type, context, message).toLocal8Bit().constData(), stderr);
  17. -
  18. - if (type == QtFatalMsg)
  19. - {
  20. - abort();
  21. - }
  22. +void otterMessageHander(QtMsgType type,
  23. + const QMessageLogContext & context,
  24. + const QString & message) {
  25. + if (message.trimmed().startsWith(QLatin1String("OpenType support missing")) || message.startsWith(QLatin1String("libpng warning: iCCP:")) || message.startsWith(QLatin1String("OpenType support missing for script")) || message.startsWith(QLatin1String("QCoreApplication::postEvent: Unexpected null receiver")) || message.startsWith(QLatin1String("QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once")) || message.startsWith(QLatin1String("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread")) || message.startsWith(QLatin1String("QFSFileEngine::open")) || message.contains(QLatin1String("::_q_startOperation was called more than once"))) {
  26. + return;
  27. + }
  28. +
  29. + fputs(qFormatLogMessage(type, context, message).toLocal8Bit().constData(), stderr);
  30. +
  31. + if (type == QtFatalMsg) {
  32. + abort();
  33. + }
  34. }
  35. #endif
  36.  
  37. -#ifdef OTTER_ENABLE_CRASHREPORTS
  38. -#ifdef Q_OS_WIN32
  39. -bool otterCrashDumpHandler(const wchar_t *dumpDirectory, const wchar_t *dumpIdentifier, void *context, EXCEPTION_POINTERS *exceptionInformation, MDRawAssertionInfo *assertionInformation, bool succeeded)
  40. -{
  41. - Q_UNUSED(context)
  42. - Q_UNUSED(exceptionInformation)
  43. - Q_UNUSED(assertionInformation)
  44. +# ifdef OTTER_ENABLE_CRASHREPORTS# ifdef Q_OS_WIN32
  45. +bool otterCrashDumpHandler(const wchar_t * dumpDirectory,
  46. + const wchar_t * dumpIdentifier, void * context, EXCEPTION_POINTERS * exceptionInformation, MDRawAssertionInfo * assertionInformation, bool succeeded) {
  47. + Q_UNUSED(context)
  48. + Q_UNUSED(exceptionInformation)
  49. + Q_UNUSED(assertionInformation)
  50.  
  51. - if (succeeded)
  52. - {
  53. - const QString dumpPath(QDir::toNativeSeparators(QString::fromWCharArray(dumpDirectory) + QDir::separator() + QString::fromWCharArray(dumpIdentifier) + QLatin1String(".dmp")));
  54. + if (succeeded) {
  55. + const QString dumpPath(QDir::toNativeSeparators(QString::fromWCharArray(dumpDirectory) + QDir::separator() + QString::fromWCharArray(dumpIdentifier) + QLatin1String(".dmp")));
  56.  
  57. - qDebug("Crash dump saved to: %s", dumpPath.toLocal8Bit().constData());
  58. + qDebug("Crash dump saved to: %s", dumpPath.toLocal8Bit().constData());
  59.  
  60. - const MainWindow *mainWindow(Application::getActiveWindow());
  61. + const MainWindow * mainWindow(Application::getActiveWindow());
  62.  
  63. - QProcess::startDetached(QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String("crash-reporter.exe")), {dumpPath, (mainWindow ? mainWindow->getUrl().toDisplayString() : QString())});
  64. - }
  65. + QProcess::startDetached(QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String("crash-reporter.exe")), {
  66. + dumpPath,
  67. + (mainWindow ? mainWindow - > getUrl().toDisplayString() : QString())
  68. + });
  69. + }
  70.  
  71. - return succeeded;
  72. + return succeeded;
  73. }
  74. #elif defined(Q_OS_LINUX)
  75. -bool otterCrashDumpHandler(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded)
  76. -{
  77. - Q_UNUSED(context)
  78. +bool otterCrashDumpHandler(const google_breakpad::MinidumpDescriptor & descriptor, void * context, bool succeeded) {
  79. + Q_UNUSED(context)
  80.  
  81. - if (succeeded)
  82. - {
  83. - qDebug("Crash dump saved to: %s", descriptor.path());
  84. + if (succeeded) {
  85. + qDebug("Crash dump saved to: %s", descriptor.path());
  86.  
  87. - const MainWindow *mainWindow(Application::getActiveWindow());
  88. + const MainWindow * mainWindow(Application::getActiveWindow());
  89.  
  90. - QProcess::startDetached(QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String("crash-reporter")), {descriptor.path(), (mainWindow ? mainWindow->getUrl().toDisplayString() : QString())});
  91. - }
  92. + QProcess::startDetached(QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QDir::separator() + QLatin1String("crash-reporter")), {
  93. + descriptor.path(),
  94. + (mainWindow ? mainWindow - > getUrl().toDisplayString() : QString())
  95. + });
  96. + }
  97.  
  98. - return succeeded;
  99. + return succeeded;
  100. }
  101. #endif
  102. #endif
  103.  
  104. -int main(int argc, char *argv[])
  105. -{
  106. - QT_REQUIRE_VERSION(argc, argv, QT_VERSION_STR)
  107. +int main(int argc, char * argv[]) {
  108. + QT_REQUIRE_VERSION(argc, argv, QT_VERSION_STR)
  109.  
  110. #if !defined(Q_OS_WIN32)
  111. - qSetMessagePattern(QLatin1String("%{if-category}%{category}: %{endif}%{message}\n"));
  112. - qInstallMessageHandler(otterMessageHander);
  113. -#endif
  114. + qSetMessagePattern(QLatin1String("%{if-category}%{category}: %{endif}%{message}\n"));
  115. + qInstallMessageHandler(otterMessageHander);#
  116. + endif
  117.  
  118. -#ifdef OTTER_ENABLE_CRASHREPORTS
  119. -#ifdef Q_OS_WIN32
  120. - new google_breakpad::ExceptionHandler(reinterpret_cast<const wchar_t*>(QStandardPaths::writableLocation(QStandardPaths::TempLocation).utf16()), 0, otterCrashDumpHandler, 0, true);
  121. +#ifdef OTTER_ENABLE_CRASHREPORTS# ifdef Q_OS_WIN32
  122. + new google_breakpad::ExceptionHandler(reinterpret_cast <
  123. + const wchar_t * > (QStandardPaths::writableLocation(QStandardPaths::TempLocation).utf16()), 0, otterCrashDumpHandler, 0, true);
  124. #elif defined(Q_OS_LINUX)
  125. - new google_breakpad::ExceptionHandler(google_breakpad::MinidumpDescriptor(QStandardPaths::writableLocation(QStandardPaths::TempLocation).toStdString()), 0, otterCrashDumpHandler, 0, true, -1);
  126. + new google_breakpad::ExceptionHandler(google_breakpad::MinidumpDescriptor(QStandardPaths::writableLocation(QStandardPaths::TempLocation).toStdString()), 0, otterCrashDumpHandler, 0, true, -1);
  127. +
  128. #endif
  129. #endif
  130.  
  131. #if QT_VERSION >= 0x050900
  132. - // Enable automatic High-DPI scaling support. This could be done with earlier Qt
  133. - // versions as well (down to 5.6), but it was rather buggy before 5.9, so we
  134. - // restrict to 5.9 and higher.
  135. - // Users can force-enable this on olde Qt versions by setting the environment
  136. - // variable `QT_AUTO_SCREEN_SCALE_FACTOR=1`.
  137. - // Note that this attribute must be enabled before the QApplication is
  138. - // constructed, hence the use of the static version of setAttribute().
  139. -// Application::setAttribute(Qt::AA_EnableHighDpiScaling, true);
  140. + // Enable automatic High-DPI scaling support. This could be done with earlier Qt
  141. + // versions as well (down to 5.6), but it was rather buggy before 5.9, so we
  142. + // restrict to 5.9 and higher.
  143. + // Users can force-enable this on olde Qt versions by setting the environment
  144. + // variable `QT_AUTO_SCREEN_SCALE_FACTOR=1`.
  145. + // Note that this attribute must be enabled before the QApplication is
  146. + // constructed, hence the use of the static version of setAttribute().
  147. + // Application::setAttribute(Qt::AA_EnableHighDpiScaling, true);
  148. #endif
  149. - // Use static version for this attribute too, for consistency with the above.
  150. - Application::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
  151. -
  152. - Application application(argc, argv);
  153. -
  154. - if (Application::isAboutToQuit() || Application::isRunning() || Application::isUpdating() || Application::getCommandLineParser()->isSet(QLatin1String("report")))
  155. - {
  156. - return 0;
  157. - }
  158. -
  159. - const QString session(Application::getCommandLineParser()->value(QLatin1String("session")).isEmpty() ? QLatin1String("default") : Application::getCommandLineParser()->value(QLatin1String("session")));
  160. - const QString startupBehavior(SettingsManager::getOption(SettingsManager::Browser_StartupBehaviorOption).toString());
  161. - const bool isPrivate(Application::getCommandLineParser()->isSet(QLatin1String("private-session")));
  162. -
  163. - if (!Application::getCommandLineParser()->value(QLatin1String("session")).isEmpty() && SessionsManager::getSession(session).isClean)
  164. - {
  165. - SessionsManager::restoreSession(SessionsManager::getSession(session), nullptr, isPrivate);
  166. - }
  167. - else if (startupBehavior == QLatin1String("showDialog") || Application::getCommandLineParser()->isSet(QLatin1String("session-chooser")) || !SessionsManager::getSession(session).isClean)
  168. - {
  169. - StartupDialog dialog(session);
  170. -
  171. - if (dialog.exec() == QDialog::Rejected)
  172. - {
  173. - return 0;
  174. - }
  175. -
  176. - SessionsManager::restoreSession(dialog.getSession(), nullptr, isPrivate);
  177. - }
  178. - else if (startupBehavior == QLatin1String("continuePrevious"))
  179. - {
  180. - SessionsManager::restoreSession(SessionsManager::getSession(QLatin1String("default")), nullptr, isPrivate);
  181. - }
  182. - else
  183. - {
  184. - SessionInformation sessionData(SessionsManager::getSession(QLatin1String("default")));
  185. - sessionData.path = QLatin1String("default");
  186. - sessionData.title = QCoreApplication::translate("main", "Default");
  187. -
  188. - Session::MainWindow window;
  189. -
  190. - if (sessionData.isValid())
  191. - {
  192. - window.geometry = sessionData.windows.value(0).geometry;
  193. - }
  194. -
  195. - if (startupBehavior != QLatin1String("startEmpty"))
  196. - {
  197. - Session::Window::History::Entry entry;
  198. -
  199. - if (startupBehavior == QLatin1String("startHomePage"))
  200. - {
  201. - entry.url = SettingsManager::getOption(SettingsManager::Browser_HomePageOption).toString();
  202. - }
  203. - else if (startupBehavior == QLatin1String("startStartPage"))
  204. - {
  205. - entry.url = QLatin1String("about:start");
  206. - }
  207. - else
  208. - {
  209. - entry.url = QLatin1String("about:blank");
  210. - }
  211. -
  212. - Session::Window::History history;
  213. - history.entries = {entry};
  214. - history.index = 0;
  215. -
  216. - Session::Window tab;
  217. - tab.history = history;
  218. -
  219. - window.windows = {tab};
  220. - window.index = 0;
  221. - }
  222. -
  223. - sessionData.windows = {window};
  224. - sessionData.index = 0;
  225. -
  226. - SessionsManager::restoreSession(sessionData, nullptr, isPrivate);
  227. - }
  228. -
  229. - Application::handlePositionalArguments(Application::getCommandLineParser());
  230. -
  231. - if (Application::getWindows().isEmpty())
  232. - {
  233. - Application::createWindow({{QLatin1String("hints"), (isPrivate ? SessionsManager::PrivateOpen : SessionsManager::DefaultOpen)}});
  234. - }
  235. -
  236. - return Application::exec();
  237. + // Use static version for this attribute too, for consistency with the above.
  238. + Application::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
  239. +
  240. + Application application(argc, argv);
  241. +
  242. + if (Application::isAboutToQuit() || Application::isRunning() || Application::isUpdating() || Application::getCommandLineParser() - > isSet(QLatin1String("report"))) {
  243. + return 0;
  244. + }
  245. +
  246. + const QString session(Application::getCommandLineParser() - > value(QLatin1String("session")).isEmpty() ? QLatin1String("default") : Application::getCommandLineParser() - > value(QLatin1String("session")));
  247. + const QString startupBehavior(SettingsManager::getOption(SettingsManager::Browser_StartupBehaviorOption).toString());
  248. + const bool isPrivate(Application::getCommandLineParser() - > isSet(QLatin1String("private-session")));
  249. +
  250. + if (!Application::getCommandLineParser() - > value(QLatin1String("session")).isEmpty() && SessionsManager::getSession(session).isClean) {
  251. + SessionsManager::restoreSession(SessionsManager::getSession(session), nullptr, isPrivate);
  252. + } else if (startupBehavior == QLatin1String("showDialog") || Application::getCommandLineParser() - > isSet(QLatin1String("session-chooser")) || !SessionsManager::getSession(session).isClean) {
  253. + StartupDialog dialog(session);
  254. +
  255. + if (dialog.exec() == QDialog::Rejected) {
  256. + return 0;
  257. + }
  258. +
  259. + SessionsManager::restoreSession(dialog.getSession(), nullptr, isPrivate);
  260. + } else if (startupBehavior == QLatin1String("continuePrevious")) {
  261. + SessionsManager::restoreSession(SessionsManager::getSession(QLatin1String("default")), nullptr, isPrivate);
  262. + } else {
  263. + SessionInformation sessionData(SessionsManager::getSession(QLatin1String("default")));
  264. + sessionData.path = QLatin1String("default");
  265. + sessionData.title = QCoreApplication::translate("main", "Default");
  266. +
  267. + Session::MainWindow window;
  268. +
  269. + if (sessionData.isValid()) {
  270. + window.geometry = sessionData.windows.value(0).geometry;
  271. + }
  272. +
  273. + if (startupBehavior != QLatin1String("startEmpty")) {
  274. + Session::Window::History::Entry entry;
  275. +
  276. + if (startupBehavior == QLatin1String("startHomePage")) {
  277. + entry.url = SettingsManager::getOption(SettingsManager::Browser_HomePageOption).toString();
  278. + } else if (startupBehavior == QLatin1String("startStartPage")) {
  279. + entry.url = QLatin1String("about:start");
  280. + } else {
  281. + entry.url = QLatin1String("about:blank");
  282. + }
  283. +
  284. + Session::Window::History history;
  285. + history.entries = {
  286. + entry
  287. + };
  288. + history.index = 0;
  289. +
  290. + Session::Window tab;
  291. + tab.history = history;
  292. +
  293. + window.windows = {
  294. + tab
  295. + };
  296. + window.index = 0;
  297. + }
  298. +
  299. + sessionData.windows = {
  300. + window
  301. + };
  302. + sessionData.index = 0;
  303. +
  304. + SessionsManager::restoreSession(sessionData, nullptr, isPrivate);
  305. + }
  306. +
  307. + Application::handlePositionalArguments(Application::getCommandLineParser());
  308. +
  309. + if (Application::getWindows().isEmpty()) {
  310. + Application::createWindow({
  311. + {
  312. + QLatin1String("hints"), (isPrivate ? SessionsManager::PrivateOpen : SessionsManager::DefaultOpen)
  313. + }
  314. + });
  315. + }
  316. +
  317. + return Application::exec();
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement