main.cpp 3.19 KB
Newer Older
1
/* This file is part of the Chakra project
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
   Copyright (C) 2011 Lukas Appelhans <l.appelhans@gmx.de>

   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 <kcmdlineargs.h>
#include <klocalizedstring.h>
#include <kuniqueapplication.h>
#include <kaboutdata.h>
#include <kdebug.h>
#include "apm.h"

int main(int argc, char** argv)
{
    KAboutData aboutData("akabei", 0, ki18n("Akabei"),
                         QByteArray("0.0.1"),
                         ki18n("Chakra's CLI package manager"),
                         KAboutData::License_GPL,
                         ki18n("(C) 2011 Lukas Appelhans"),
                         ki18n("<a href=\"mailto:boom1992@chakra-project.org\">boom1992@chakra-project.org</a>"));
 
    aboutData.addAuthor(ki18n("Lukas Appelhans"), ki18n("Maintainer"), "boom1992@chakra-project.org");
    KCmdLineArgs::init(argc, argv, &aboutData);

    KCmdLineOptions options;
Lukas Appelhans's avatar
Lukas Appelhans committed
30 31 32 33 34 35 36
    
    options.add("D", ki18n("Database operation"));
    
    options.add("Q", ki18n("Query operation"));
    
    options.add("R", ki18n("Remove operation"));
    
37 38 39
    options.add("S", ki18n("Sync operation"));
    options.add("y", ki18n("Refresh database"));
    options.add("u", ki18n("Update system"));
Lukas Appelhans's avatar
Lukas Appelhans committed
40 41
    
    options.add("U", ki18n("Upgrade operation"));
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

    KCmdLineArgs::addCmdLineOptions(options);

    // Add options from other components
    KUniqueApplication::addCmdLineOptions();
    
    if (!KUniqueApplication::start()) {
       fprintf(stderr, "Akabei is already running!\n");
       return 0;
    }
    
    KUniqueApplication app;

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    
    QList<APM::Operation> list;
    APM::OperationType type = APM::NoType;
    
Lukas Appelhans's avatar
Lukas Appelhans committed
60 61 62 63 64 65 66
    if (args->isSet("D")) {
        type = APM::DatabaseOperation;
    } else if (args->isSet("Q")) {
        type = APM::QueryOperation;
    } else if (args->isSet("R")) {
        type = APM::RemoveOperation;
    } else if (args->isSet("S")) {
67 68 69
        type = APM::SyncOperation;
        if (args->isSet("y"))
            list.append(APM::UpdateDatabases);
Lukas Appelhans's avatar
Lukas Appelhans committed
70
        if (args->isSet("u"))
71
            list.append(APM::UpdateSystem);
Lukas Appelhans's avatar
Lukas Appelhans committed
72 73 74 75 76
    } else if (args->isSet("U")) {
        type = APM::UpgradeOperation;
    } else {
       fprintf(stderr, "Please select an operation to do!\nCall akabei --help for explanation.\n");
       return app.exec();
77 78 79 80
    }
    
    QStringList rest;

Lukas Appelhans's avatar
Lukas Appelhans committed
81
    for (int i = 0; i < args->count(); i++) {
82 83 84 85 86
       rest << args->arg(i);
    }
     
    args->clear(); // Free up some memory
    
87
    APM apm(type, list, rest);
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

    /* // A binary option (on / off)
     if (args->isSet("some-option"))
        ....

     // An option which takes an additional argument
     QString anotherOptionArg = args->getOption("another-option");

     // Arguments (e.g. files to open)
     for(int i = 0; i < args->count(); i++) // Counting start at 0!
     {
        openFile( args->arg(i));
        // Or more convenient:
        // openUrl( args->url(i));

     }

     args->clear(); // Free up some memory.
     ....
  }*/
    return app.exec();
109
}