main.mm 2.96 KB
Newer Older
1
/*
2
 *  Copyright (C) 2015-2016 Savoir-faire Linux Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.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 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 */
19 20 21 22

#import <AppKit/NSApplication.h>

//Qt
23
#import <qapplication.h>
24
#import <globalinstances.h>
25 26
#import <QDebug>
#import <QDir>
27 28
#import <QTranslator>
#import <QLocale>
29

30 31
//LRC
#import <personmodel.h>
32
#import <recentmodel.h>
Alexandre Lision's avatar
Alexandre Lision committed
33 34
#import <categorizedhistorymodel.h>
#import <localhistorycollection.h>
35
#import <numbercategorymodel.h>
36
#import <callmodel.h>
37

38
#import "backends/AddressBookBackend.h"
39 40
#import "delegates/ImageManipulationDelegate.h"

41
int main(int argc, const char *argv[]) {
42

43 44 45 46 47 48
    QDir dir(QString::fromUtf8(argv[0]));
    dir.cdUp();
    dir.cdUp();
    dir.cd("Plugins");
    QCoreApplication::addLibraryPath(dir.absolutePath());
    qDebug() << "" << QCoreApplication::libraryPaths();
49 50 51 52
    //Qt event loop will override native event loop
    QApplication* app = new QApplication(argc, const_cast<char**>(argv));
    app->setAttribute(Qt::AA_MacPluginApplication);

53
    dir.cdUp();
54 55 56 57 58 59 60 61 62 63

    //We need to check if primary language is an English variant (en, en-CA etc...) before installing a translator
    NSString* lang = [[NSLocale preferredLanguages] objectAtIndex:0];
    if (![lang containsString:@"en"]) {
        QTranslator translator;
        if (translator.load(QLocale::system(), "lrc", "_", dir.absolutePath()+"/Resources/QtTranslations")) {
            app->installTranslator(&translator);
        } else {
            NSLog(@"Couldn't load qt translator");
        }
64 65
    }

66
    CallModel::instance();
67
    CategorizedHistoryModel::instance().addCollection<LocalHistoryCollection>(LoadOptions::FORCE_ENABLED);
Alexandre Lision's avatar
Alexandre Lision committed
68

69 70 71
    /* make sure basic number categories exist, in case user has no contacts
     * from which these would be automatically created
     */
72 73
    NumberCategoryModel::instance().addCategory("work", QVariant());
    NumberCategoryModel::instance().addCategory("home", QVariant());
74

75
    GlobalInstances::setPixmapManipulator(std::unique_ptr<Interfaces::ImageManipulationDelegate>(new Interfaces::ImageManipulationDelegate()));
76
    PersonModel::instance().addCollection<AddressBookBackend>(LoadOptions::FORCE_ENABLED);
77
    RecentModel::instance(); // Make sure RecentModel is initialized before showing UI
78 79 80

    return NSApplicationMain(argc, argv);
}