~alecu/unity-scope-click/uninstallable-scopes

« back to all changes in this revision

Viewing changes to libclickscope/click/interface.cpp

  • Committer: Alejandro J. Cura
  • Date: 2014-06-12 21:05:25 UTC
  • Revision ID: alecu@canonical.com-20140612210525-g9jyrd3z66468gfv
A few refactorings to ease the following branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
343
343
    return manifest;
344
344
}
345
345
 
346
 
void Interface::get_manifests(std::function<void(ManifestList, ManifestError)> callback)
 
346
void Interface::get_manifests(std::function<void(ManifestList, InterfaceError)> callback)
347
347
{
348
348
    std::string command = "click list --manifest";
349
349
    qDebug() << "Running command:" << command.c_str();
350
 
    run_process(command, [callback](int code, const std::string& stdout_data, const std::string&) {
 
350
    run_process(command, [callback](int code, const std::string& stdout_data, const std::string& stderr_data) {
351
351
        if (code == 0) {
352
352
            try {
353
353
                ManifestList manifests = manifest_list_from_json(stdout_data);
354
 
                callback(manifests, ManifestError::NoError);
 
354
                callback(manifests, InterfaceError::NoError);
355
355
            } catch (...) {
356
 
                callback(ManifestList(), ManifestError::ParseError);
 
356
                qWarning() << "Can't parse 'click list --manifest' output: " << QString::fromStdString(stdout_data);
 
357
                callback(ManifestList(), InterfaceError::ParseError);
357
358
            }
358
359
        } else {
359
 
            callback(ManifestList(), ManifestError::CallError);
 
360
            qWarning() << "Error" << code << "running 'click list --manifest': " << QString::fromStdString(stderr_data);
 
361
            callback(ManifestList(), InterfaceError::CallError);
360
362
        }
361
363
    });
362
364
}
363
365
 
364
366
void Interface::get_manifest_for_app(const std::string &app_id,
365
 
                                     std::function<void(Manifest, ManifestError)> callback)
 
367
                                     std::function<void(Manifest, InterfaceError)> callback)
366
368
{
367
369
    std::string command = "click info " + app_id;
368
370
    qDebug() << "Running command:" << command.c_str();
370
372
        if (code == 0) {
371
373
            try {
372
374
                Manifest manifest = manifest_from_json(stdout_data);
373
 
                callback(manifest, ManifestError::NoError);
 
375
                callback(manifest, InterfaceError::NoError);
374
376
            } catch (...) {
375
 
                callback(Manifest(), ManifestError::ParseError);
 
377
                callback(Manifest(), InterfaceError::ParseError);
376
378
            }
377
379
        } else {
378
 
            callback(Manifest(), ManifestError::CallError);
 
380
            callback(Manifest(), InterfaceError::CallError);
379
381
        }
380
382
    });
381
383
}
382
384
 
383
385
void Interface::get_dotdesktop_filename(const std::string &app_id,
384
 
                                        std::function<void(std::string, ManifestError)> callback)
 
386
                                        std::function<void(std::string, InterfaceError)> callback)
385
387
{
386
 
    get_manifest_for_app(app_id, [app_id, callback] (Manifest manifest, ManifestError error) {
 
388
    get_manifest_for_app(app_id, [app_id, callback] (Manifest manifest, InterfaceError error) {
387
389
        qDebug() << "in get_dotdesktop_filename callback";
388
390
 
389
 
        if (error != ManifestError::NoError){
 
391
        if (error != InterfaceError::NoError){
390
392
            callback(std::string("Internal Error"), error);
391
393
            return;
392
394
        }
394
396
 
395
397
        if (!manifest.name.empty()) {
396
398
            std::string ddstr = manifest.name + "_" + manifest.first_app_name + "_" + manifest.version + ".desktop";
397
 
            callback(ddstr, ManifestError::NoError);
 
399
            callback(ddstr, InterfaceError::NoError);
398
400
        } else {
399
401
            qCritical() << "Warning: no manifest found for " << app_id.c_str();
400
 
            callback(std::string("Not found"), ManifestError::CallError);
 
402
            callback(std::string("Not found"), InterfaceError::CallError);
401
403
        }
402
404
    });
403
405
}