Ejemplo n.º 1
0
//========PUBLIC FUNCTIONS==========
void Interface::start()
{
    char ch = ' ';

    while(ch != 'q')
    {
        checkRelation();

        printMainMenu();
        setStatus(""); //reset status message

        cout << "Choice: ";
        cin >> ch;
        switch(ch)
        {
        case 'a':
            about();
            break;
        case 's':
            enterTheMatrixQuestion();
            break;
        case '1':
            addCompOrPerson();
            break;
        case '2':
            viewCompsOrPersons();
            break;
        case '3':
            settingsMain();
            break;
        default:
            break;
        }
    }
}
Ejemplo n.º 2
0
bool CachedProvider::storeInCache(const QString &identifier, const QImage &comic, const Settings &info)
{
    const QString path = identifierToPath(identifier);

    int index = identifier.indexOf(QLatin1Char(':'));
    const QString comicName = identifier.mid(0, index);
    const QString pathMain = identifierToPath(comicName);
    const QString dirPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/plasma_engine_comic/") ;

    if (!info.isEmpty()) {
        QSettings settings(path + QLatin1String(".conf"), QSettings::IniFormat);
        QSettings settingsMain(pathMain + QLatin1String(".conf"), QSettings::IniFormat);

        for (Settings::const_iterator i = info.constBegin(); i != info.constEnd(); ++i) {
                if ((i.key() == QLatin1String("firstStripIdentifier")) || (i.key() == QLatin1String("title")) ||
                     (i.key() == QLatin1String("lastCachedStripIdentifier")) || (i.key() == QLatin1String("suffixType")) ||
                     (i.key() == QLatin1String("shopUrl")) || (i.key() == QLatin1String("isLeftToRight")) ||
                     (i.key() == QLatin1String("isTopToBottom"))) {
                    settingsMain.setValue(i.key(), i.value());
                } else {
                    settings.setValue(i.key(), i.value());
                }
        }

        QStringList comics;
        if (settingsMain.contains(QLatin1String("comics"))) {
            comics = settingsMain.value(QLatin1String("comics"), QStringList()).toStringList();
        } else {
            //existing strips haven't been stored in the conf-file yet, do that now, oldest first, newest last
            QDir dir(dirPath);
            comics = dir.entryList(QStringList() << QUrl::toPercentEncoding(comicName + ':') + '*', QDir::Files, QDir::Time | QDir::Reversed);
            QStringList::iterator it = comics.begin();
            while (it != comics.end()) {
                //only count images, not the conf files
                if ((*it).endsWith(QLatin1String(".conf"))) {
                    it = comics.erase(it);
                } else {
                    ++it;
                }
            }
        }
        comics.append(QUrl::toPercentEncoding(identifier));

        const int limit = CachedProvider::maxComicLimit();
        //limit is on
        if (limit > 0) {
            qDebug() << QLatin1String("MaxComicLimit on.");
            int comicsToRemove = comics.count() - limit;
            QStringList::iterator it = comics.begin();
            while (comicsToRemove > 0 && it != comics.end()) {
                qDebug() << QLatin1String("Remove file") << (dirPath + (*it));
                QFile::remove(dirPath + (*it));
                QFile::remove(dirPath + (*it) + QLatin1String(".conf"));
                it = comics.erase(it);
                -- comicsToRemove;
            }
        }
        settingsMain.setValue(QLatin1String("comics"), comics);
    }

    return comic.save(path, "PNG");
}