File indexing completed on 2024-04-21 04:20:47

0001 /*
0002    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0003    Copyright (c) 2015,2016 Martin Koller <kollix@aon.at>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 
0029 #include <KAboutData>
0030 
0031 #include "kpVersion.h"
0032 #include "mainWindow/kpMainWindow.h"
0033 #include <kolourpaintlicense.h>
0034 #include <document/kpDocument.h>
0035 
0036 #include <QApplication>
0037 #include <QCommandLineParser>
0038 #include <QImageReader>
0039 #include <QDir>
0040 #include <KLocalizedString>
0041 
0042 int main(int argc, char *argv [])
0043 {
0044   QApplication app(argc, argv);
0045 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0046   QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0047 #endif
0048 
0049   KLocalizedString::setApplicationDomain("kolourpaint");
0050 
0051   KAboutData aboutData
0052   (
0053     QStringLiteral("kolourpaint"),
0054     i18n("KolourPaint"),
0055     QStringLiteral(KOLOURPAINT_VERSION_STRING),
0056     i18n("Paint Program by KDE"),
0057     KAboutLicense::Custom,
0058     QString(), // copyright statement - see license instead
0059     QString(), // other text
0060     QStringLiteral("http://www.kolourpaint.org/")   // home page
0061   );
0062 
0063   // (this is _not_ the same as KAboutLicense::BSD)
0064   aboutData.setLicenseText(i18n(kpLicenseText));
0065   aboutData.setDesktopFileName(QStringLiteral("org.kde.kolourpaint"));
0066 
0067   // Please add yourself here if you feel you're missing.
0068   // SYNC: with AUTHORS
0069 
0070   aboutData.addAuthor(i18n("Clarence Dang"), i18n("Project Founder"), QStringLiteral("dang@kde.org"));
0071 
0072   aboutData.addAuthor(i18n("Thurston Dang"), i18n("Chief Investigator"),
0073                       QStringLiteral("thurston_dang@users.sourceforge.net"));
0074 
0075   aboutData.addAuthor(i18n("Martin Koller"), i18n("Scanning Support, Alpha Support, Current Maintainer"),
0076                       QStringLiteral("kollix@aon.at"));
0077 
0078   aboutData.addAuthor(i18n("Kristof Borrey"), i18n("Icons"), QStringLiteral("borrey@kde.org"));
0079   aboutData.addAuthor(i18n("Tasuku Suzuki"), i18n("InputMethod Support"), QStringLiteral("stasuku@gmail.com"));
0080   aboutData.addAuthor(i18n("Kazuki Ohta"), i18n("InputMethod Support"), QStringLiteral("mover@hct.zaq.ne.jp"));
0081   aboutData.addAuthor(i18n("Nuno Pinheiro"), i18n("Icons"), QStringLiteral("nf.pinheiro@gmail.com"));
0082   aboutData.addAuthor(i18n("Danny Allen"), i18n("Icons"), QStringLiteral("dannya40uk@yahoo.co.uk"));
0083   aboutData.addAuthor(i18n("Mike Gashler"), i18n("Image Effects"), QStringLiteral("gashlerm@yahoo.com"));
0084 
0085   aboutData.addAuthor(i18n("Laurent Montel"), i18n("KDE 4 Porting"), QStringLiteral("montel@kde.org"));
0086   aboutData.addAuthor(i18n("Christoph Feck"), i18n("KF 5 Porting"), QStringLiteral("cfeck@kde.org"));
0087 
0088   aboutData.addCredit(i18n("Thanks to the many others who have helped to make this program possible."));
0089 
0090   QCommandLineParser cmdLine;
0091   KAboutData::setApplicationData(aboutData);
0092   QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("kolourpaint"), QApplication::windowIcon()));
0093   cmdLine.addPositionalArgument(QStringLiteral("files"), i18n("Image files to open, optionally"), QStringLiteral("[files...]"));
0094 
0095   aboutData.setupCommandLine(&cmdLine);
0096   cmdLine.addOption(QCommandLineOption(QStringLiteral("mimetypes"), i18n("List all readable image MIME types")));
0097   cmdLine.addOption(QCommandLineOption(QStringLiteral("new"), i18n("Start with new image using given size"), i18n("[width]x[height]")));
0098   cmdLine.process(app);
0099   aboutData.processCommandLine(&cmdLine);
0100 
0101   // produce a list of MimeTypes which kolourpaint can handle (can be used inside the .desktop file)
0102   if ( cmdLine.isSet(QStringLiteral("mimetypes")) )
0103   {
0104     const QList<QByteArray> types = QImageReader::supportedMimeTypes();
0105     for (const QByteArray &type : types)
0106     {
0107       if ( !type.isEmpty() )
0108         printf("%s;", type.constData());
0109     }
0110 
0111     printf("\n");
0112 
0113     return 0;
0114   }
0115 
0116   if ( app.isSessionRestored() )
0117   {
0118     // Creates a kpMainWindow using the default constructor and then
0119     // calls kpMainWindow::readProperties().
0120     kRestoreMainWindows<kpMainWindow>();
0121   }
0122   else
0123   {
0124     kpMainWindow *mainWindow;
0125     QStringList args = cmdLine.positionalArguments();
0126 
0127     if ( args.count() >= 1 )
0128     {
0129       for (int i = 0; i < args.count(); i++)
0130       {
0131         mainWindow = new kpMainWindow(QUrl::fromUserInput(args[i], QDir::currentPath(), QUrl::AssumeLocalFile));
0132         mainWindow->show();
0133       }
0134     }
0135     else
0136     {
0137       kpDocument *doc = nullptr;
0138       QString sizeStr = cmdLine.value(QStringLiteral("new"));
0139 
0140       if ( !sizeStr.isEmpty() )
0141       {
0142         QStringList dimensions = sizeStr.split(QLatin1Char('x'));
0143         if ( dimensions.count() == 2 )
0144         {
0145           unsigned int w = dimensions[0].toUInt();
0146           unsigned int h = dimensions[1].toUInt();
0147 
0148           if ( (w > 0) && (h > 0) )
0149             doc = new kpDocument(w, h, nullptr);
0150         }
0151       }
0152 
0153       if ( doc )
0154         mainWindow = new kpMainWindow(doc);
0155       else
0156         mainWindow = new kpMainWindow();
0157 
0158       mainWindow->show();
0159     }
0160   }
0161 
0162   return QApplication::exec();
0163 }