diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a1f310..0e06460 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,67 +1,68 @@ ########### kdiff3 KPart ############### find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Parts WidgetsAddons) set(kdiff3part_PART_SRCS kdiff3_part.cpp kdiff3.cpp directorymergewindow.cpp merger.cpp pdiff.cpp difftextwindow.cpp diff.cpp optiondialog.cpp mergeresultwindow.cpp fileaccess.cpp gnudiff_analyze.cpp gnudiff_io.cpp gnudiff_xmalloc.cpp common.cpp smalldialogs.cpp progress.cpp ProgressProxyExtender.cpp PixMapUtils.cpp MergeFileInfos.cpp Utils.cpp selection.cpp cvsignorelist.cpp SourceData.cpp - Overview.cpp ) + Overview.cpp + Logging.cpp ) add_library(kdiff3part MODULE ${kdiff3part_PART_SRCS}) set_target_properties(kdiff3part PROPERTIES DEFINE_SYMBOL KDIFF3_PART) target_compile_features(kdiff3part PRIVATE ${needed_features}) target_link_libraries(kdiff3part ${KDiff3_LIBRARIES} KF5::Parts) target_compile_definitions(kdiff3part PRIVATE -DTRANSLATION_DOMAIN=\"kdiff3\") install(TARGETS kdiff3part DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/parts ) ########### kdiff3 executable ############### find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Parts WidgetsAddons Config) set(kdiff3_SRCS main.cpp kdiff3_shell.cpp ${kdiff3part_PART_SRCS} ) add_executable(kdiff3 ${kdiff3_SRCS}) target_link_libraries(kdiff3 KF5::ConfigCore KF5::ConfigGui KF5::Parts ${KDiff3_LIBRARIES} ) target_compile_features(kdiff3 PRIVATE ${needed_features}) install(TARGETS kdiff3 ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install( FILES kdiff3part.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) install( FILES kdiff3_part.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/kdiff3part ) install( FILES kdiff3_shell.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/kdiff3 ) #install( PROGRAMS kdiff3.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) install( PROGRAMS org.kde.kdiff3.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) install( FILES org.kde.kdiff3.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) add_subdirectory(icons) diff --git a/src/Logging.cpp b/src/Logging.cpp new file mode 100644 index 0000000..32226cd --- /dev/null +++ b/src/Logging.cpp @@ -0,0 +1,22 @@ +/** + * Copyright (C) 2019 Michael Reeves + * + * This file is part of KDiff3. + * + * KDiff3 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * KDiff3 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KDiff3. If not, see . + */ + +#include "Logging.h" + +Q_LOGGING_CATEGORY(kdeMain, "org.kde.kdiff3") diff --git a/src/main.cpp b/src/main.cpp index 5f338de..33f708c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,183 +1,180 @@ /*************************************************************************** * Copyright (C) 2003-2007 by Joachim Eibl * * Copyright (C) 2018 Michael Reeves reeves.87@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "kdiff3_shell.h" #include "version.h" #include "Logging.h" #ifndef Q_WIN_OS #include #endif // !Q_WIN_OS #include #include #include #include #include #include #include #include #include #include #include #include -#include - -Q_LOGGING_CATEGORY(kdeMain, "org.kde.kdiff3") void initialiseCmdLineArgs(QCommandLineParser* cmdLineParser) { QString configFileName = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, "kdiff3rc"); QFile configFile(configFileName); QString ignorableOptionsLine = "-u;-query;-html;-abort"; if(configFile.open(QIODevice::ReadOnly)) { QTextStream ts(&configFile); while(!ts.atEnd()) { QString line = ts.readLine(); if(line.startsWith(QLatin1String("IgnorableCmdLineOptions="))) { int pos = line.indexOf('='); if(pos >= 0) { ignorableOptionsLine = line.mid(pos + 1); } break; } } } //support our own old preferences this is obsolete QStringList sl = ignorableOptionsLine.split(','); if(!sl.isEmpty()) { QStringList ignorableOptions = sl.front().split(';'); for(QStringList::iterator i = ignorableOptions.begin(); i != ignorableOptions.end(); ++i) { (*i).remove('-'); if(!(*i).isEmpty()) { if(i->length() == 1) { cmdLineParser->addOption(QCommandLineOption(QStringList() << *i << QLatin1String("ignore"), i18n("Ignored. (User defined.)"))); } else { cmdLineParser->addOption(QCommandLineOption(QStringList() << *i, i18n("Ignored. (User defined.)"))); } } } } } int main(int argc, char* argv[]) { const QLatin1String appName("kdiff3"); QApplication app(argc, argv); // KAboutData and QCommandLineParser depend on this being setup. KLocalizedString::setApplicationDomain(appName.data()); KCrash::initialize(); const QString i18nName = i18n("KDiff3"); QString appVersion(KDIFF3_VERSION_STRING); if(sizeof(void*) == 8) appVersion += i18n(" (64 bit)"); else if(sizeof(void*) == 4) appVersion += i18n(" (32 bit)"); const QString description = i18n("Tool for Comparison and Merge of Files and Directories"); const QString copyright = i18n("(c) 2002-2014 Joachim Eibl, (c) 2017 Michael Reeves KF5/Qt5 port"); const QString homePage = QStringLiteral("https://kde.org/applications/development/kdiff3"); KAboutData aboutData(appName, i18nName, appVersion, description, KAboutLicense::GPL_V2, copyright, QString(), homePage); KAboutData::setApplicationData(aboutData); QCommandLineParser* cmdLineParser = KDiff3Shell::getParser(); cmdLineParser->setApplicationDescription(aboutData.shortDescription()); aboutData.setupCommandLine(cmdLineParser); initialiseCmdLineArgs(cmdLineParser); // ignorable command options cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("m") << QLatin1String("merge"), i18n("Merge the input."))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("b") << QLatin1String("base"), i18n("Explicit base file. For compatibility with certain tools."), QLatin1String("file"))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("o") << QLatin1String("output"), i18n("Output file. Implies -m. E.g.: -o newfile.txt"), QLatin1String("file"))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("out"), i18n("Output file, again. (For compatibility with certain tools.)"), QLatin1String("file"))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("auto"), i18n("No GUI if all conflicts are auto-solvable. (Needs -o file)"))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("qall"), i18n("Do not solve conflicts automatically."))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("L1"), i18n("Visible name replacement for input file 1 (base)."), QLatin1String("alias1"))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("L2"), i18n("Visible name replacement for input file 2."), QLatin1String("alias2"))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("L3"), i18n("Visible name replacement for input file 3."), QLatin1String("alias3"))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("L") << QLatin1String("fname alias"), i18n("Alternative visible name replacement. Supply this once for every input."))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("cs"), i18n("Override a config setting. Use once for every setting. E.g.: --cs \"AutoAdvance=1\""), QLatin1String("string"))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("confighelp"), i18n("Show list of config settings and current values."))); cmdLineParser->addOption(QCommandLineOption(QStringList() << QLatin1String("config"), i18n("Use a different config file."), QLatin1String("file"))); // other command options cmdLineParser->addPositionalArgument(QLatin1String("[File1]"), i18n("file1 to open (base, if not specified via --base)")); cmdLineParser->addPositionalArgument(QLatin1String("[File2]"), i18n("file2 to open")); cmdLineParser->addPositionalArgument(QLatin1String("[File3]"), i18n("file3 to open")); bool isAtty = true; #ifndef Q_OS_WIN isAtty = isatty(fileno(stderr)) == 1;//will be true for redirected output as well #endif /* QCommandLineParser::process does what is expected on windows or when running from a commandline. However, it only accounts for a lackof terminal output on windows. */ if(isAtty) { cmdLineParser->process(QCoreApplication::arguments()); } else { /* There is no terminal connected so don't just exit mysteriously exit on error. */ if(!cmdLineParser->parse(QCoreApplication::arguments())) { QString errorMessage = cmdLineParser->errorText(); KMessageBox::error(nullptr, "

" + errorMessage + "

" + i18n("See kdiff3 --help for supported options.") + "
", aboutData.displayName()); exit(1); } if(cmdLineParser->isSet(QStringLiteral("version"))) { KMessageBox::information(nullptr, aboutData.displayName() + ' ' + aboutData.version(), aboutData.displayName()); exit(0); } if(cmdLineParser->isSet(QStringLiteral("help"))) { KMessageBox::information(nullptr, "
" + cmdLineParser->helpText() + "
", aboutData.displayName()); exit(0); } } aboutData.processCommandLine(cmdLineParser); KDiff3Shell* p = new KDiff3Shell(); p->show(); //p->setWindowState( p->windowState() | Qt::WindowActive ); // Patch for ubuntu: window not active on startup //app.installEventFilter( new CFilter ); int retVal = app.exec(); /* if (QApplication::clipboard()->text().size() == 0) QApplication::clipboard()->clear(); // Patch for Ubuntu: Fix issue with Qt clipboard*/ return retVal; }