Logo Search packages:      
Sourcecode: qapt version File versions  Download package

bool QApt::Backend::loadSelections ( const QString &  path  )  [slot]

Reads and applies selections from a text file generated from either saveSelections() or from Synaptic

Parameters:
path The path from which to read the selection list
Returns:
true if reading/marking succeeded

false if the reading/marking failed

Definition at line 703 of file backend.cpp.

References QApt::Package::ToInstall, and QApt::Package::ToRemove.

{
    Q_D(Backend);

    QFile file(path);
    if (!file.open(QFile::ReadOnly)) {
        return false;
    }

    QTextStream in(&file);

    QString line;

    string stdName;
    string stdAction;
    QString packageName;
    QString packageAction;

    QMap<QString, int> actionMap;
    do {
        line = in.readLine();
        if (line.isEmpty() || line.at(0) == '#') {
            continue;
        }
        line = line.simplified();

        const char *C = line.toStdString().data();
        if (!ParseQuoteWord(C, stdName)) {
            return false;
        }
        packageName = QString::fromStdString(stdName);

        if (!ParseQuoteWord(C, stdAction)) {
            return false;
        }
        packageAction = QString::fromStdString(stdAction);

        if (packageAction.at(0) == 'i') {
            actionMap[packageName] = Package::ToInstall;
        } else if ((packageAction.at(0) == 'd') || (packageAction.at(0) == 'u')) {
            actionMap[packageName] = Package::ToRemove;
        }
    } while (!line.isNull());

    if (actionMap.isEmpty()) {
       return false;
    }

    pkgDepCache &cache = *d->cache->depCache();
    pkgProblemResolver Fix(&cache);
    // XXX Should protect whatever is already selected in the cache.

    pkgCache::PkgIterator pkgIter;
    QMap<QString, int>::const_iterator mapIter = actionMap.begin();
    while (mapIter != actionMap.end()) {
        pkgIter = d->cache->depCache()->FindPkg(mapIter.key().toStdString());
        if (pkgIter.end()) {
            return false;
        }

        Fix.Clear(pkgIter);
        Fix.Protect(pkgIter);

        switch (mapIter.value()) {
           case Package::ToInstall:
               if(_config->FindB("Volatile::SetSelectionDoReInstall",false)) {
                   cache.SetReInstall(pkgIter, true);
               }
               if(_config->FindB("Volatile::SetSelectionsNoFix",false)) {
                   cache.MarkInstall(pkgIter, false);
               } else {
                   cache.MarkInstall(pkgIter, true);
               }
               break;
           case Package::ToRemove:
               Fix.Remove(pkgIter);
               cache.MarkDelete(pkgIter, false);
               break;
        }
        ++mapIter;
    }

    Fix.InstallProtect();
    Fix.Resolve(true);

    return true;
}


Generated by  Doxygen 1.6.0   Back to index