示例#1
0
int main(int argc, char** argv)
{
    fcitx_utils_init_as_daemon();

    if (isRunning()) {
        exit(1);
    }

    QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
    QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

    QTranslator translator;
    if (translator.load(QString(getQimpanelSharePath("zh_CN.qm"))) == false)
        qDebug() << "load qm error.";

    QApplication *app = new QApplication(argc, argv);
    app->installTranslator(&translator);
    app->setApplicationName("fcitx-qimpanel");

    int waittTick = 0;
    int waitTime = 10;
    while (waittTick ++ < waitTime && fcitxIsNotRunning()) {
        qDebug() << "Fcitx not running.";
        sleep(1);
    }
    qDebug() << "fcitxIsNotRunning():" << fcitxIsNotRunning();
    if (waittTick >= waitTime)
        return -1;

    MainController *ctrl = MainController::self();

    signal(SIGHUP, sigRoutine);

    app->setQuitOnLastWindowClosed(false);
    app->exec();

    delete ctrl;
    delete app;
    return 0;
}
void SystemTrayMenu::doUpdateSkinListMenu()
{
    int i;
    size_t len;
    QDir skinDir;
    bool checked = false;
    MyAction *firstMenu = NULL, *menu;
    QFileInfoList list;
    QFileInfoList::Iterator iter;
    QString skinName = MainController::self()->getSkinName();
    SkinClass skinClass;
    bool localExist;
    MyAction *skinNameMenu = NULL;
    mSkinMenu->clear();
    QString localSkinPath = qgetenv("HOME") + "/.config/fcitx-qimpanel/skin/";

    for (i = 0; i < 1; i ++) {
        skinDir = QDir(localSkinPath);
        if (!skinDir.exists())
            continue;

        skinDir.setFilter(QDir::Dirs);
        list = skinDir.entryInfoList();
        for (iter = list.begin(); iter != list.end(); ++ iter) {
            if (iter->isDir() && "." != iter->fileName() && ".." != iter->fileName()) {
                QFile fcitxSkinConfFile(iter->absoluteFilePath() + "/fcitx_skin.conf");
                QFile sogouSkinConfFile(iter->absoluteFilePath() + "/skin.ini");

                if (fcitxSkinConfFile.exists()){
                    skinClass = FCITX;
                }else continue;

                menu = new MyAction(iter->fileName(), this);
                menu->setMyActionType(SkinAction);
                menu->setSkinPath(iter->absoluteFilePath() + "/");
                menu->setSkinClass(skinClass);
                mSkinMenu->addAction(menu);
                if (firstMenu == NULL)
                    firstMenu = menu;
                menu->setCheckable(true);
                if (iter->fileName() == skinName) {
                    checked = true;
                    menu->setChecked(true);
                    skinNameMenu = menu;
                }
            }
        }
    }

    char* ukSkinPath = getQimpanelSharePath("skin");

    for (i = 0; i < 1; i ++) {
        skinDir = QDir(ukSkinPath);
        if (!skinDir.exists())
            continue;

        skinDir.setFilter(QDir::Dirs);
        list = skinDir.entryInfoList();
        for (iter = list.begin(); iter != list.end(); ++ iter) {
            if (iter->isDir() && "." != iter->fileName() && ".." != iter->fileName()) {
                QFile fcitxSkinConfFile(iter->absoluteFilePath() + "/fcitx_skin.conf");
                QFile sogouSkinConfFile(iter->absoluteFilePath() + "/skin.ini");

                if (fcitxSkinConfFile.exists()){
                    skinClass = FCITX;
                }else continue;

                //check if exist in local
                localExist = false;
                QList<QAction *> localExistList = this->actions();
                QList<QAction *>::iterator localExistIter;
                for (localExistIter = localExistList.begin();
                    localExistIter != localExistList.end(); ++ localExistIter)
                {
                    if (((MyAction *)(*localExistIter))->text() == iter->fileName()) {
                        localExist = true;
                        break;
                    }
                }
                if (localExist)
                    continue;

                menu = new MyAction(iter->fileName(), this);
                menu->setMyActionType(SkinAction);
                //qDebug() << iter->absoluteFilePath();
                menu->setSkinPath(iter->absoluteFilePath() + "/");
                menu->setSkinClass(skinClass);
                mSkinMenu->addAction(menu);
                if (firstMenu == NULL)
                    firstMenu = menu;
                menu->setCheckable(true);
                if (iter->fileName() == skinName) {
                    checked = true;
                    menu->setChecked(true);
                    skinNameMenu = menu;
                }
            }
        }
    }

    char **skinPath = FcitxXDGGetPathWithPrefix(&len, "skin");
    for (i = 0; i < len; i ++) {
        skinDir = QDir(skinPath[i]);
        if (!skinDir.exists())
            continue;

        skinDir.setFilter(QDir::Dirs);
        list = skinDir.entryInfoList();
        for (iter = list.begin(); iter != list.end(); ++ iter) {
            if (iter->isDir() && "." != iter->fileName() && ".." != iter->fileName()) {
                QFile fcitxSkinConfFile(iter->absoluteFilePath() + "/fcitx_skin.conf");
                QFile sogouSkinConfFile(iter->absoluteFilePath() + "/skin.ini");

                if (fcitxSkinConfFile.exists()){
                    skinClass = FCITX;
                }else continue;

                menu = new MyAction(iter->fileName(), this);
                menu->setMyActionType(SkinAction);
                menu->setSkinPath(iter->absoluteFilePath() + "/");
                menu->setSkinClass(skinClass);
                mSkinMenu->addAction(menu);
                if (firstMenu == NULL)
                    firstMenu = menu;
                menu->setCheckable(true);
                if (iter->fileName() == skinName) {
                    checked = true;
                    menu->setChecked(true);
                    skinNameMenu = menu;
                }
            }
        }
    }

    if (!checked)
        firstMenu->setChecked(true);

    if (skinNameMenu == NULL)
        skinNameMenu = firstMenu;

    FcitxXDGFreePath(skinPath);

    skinMenuItemOnClick(skinNameMenu);
    this->addMenu(mSkinMenu);
}