~ubuntu-branches/ubuntu/trusty/checkbox/trusty

« back to all changes in this revision

Viewing changes to checkbox-gui/gui-engine/gui-engine.cpp

  • Committer: Daniel Manrique
  • Date: 2014-04-09 14:27:44 UTC
  • mfrom: (1992.1.11 ubuntu_checkbox)
  • Revision ID: roadmr@ubuntu.com-20140409142744-tpzj2zlqeuob4sl8
Tags: 0.17.6-0ubuntu6
* Use select_jobs to ensure whitelist order is preserved (LP: #1213893)
* Use partial_id to avoid showing overly-long, namespaced job names
  (LP: #1297500)
* Enable customization of some checkbox-gui parameters (LP: #1303849)
* Send test results to Launchpad (LP: #1302615)

Show diffs side-by-side

added added

removed removed

Lines of Context:
490
490
 
491
491
            // First time round, fill in our whitelist member
492
492
            if (!initialised) {
493
 
                whitelist.insert(child->object_path,true);
 
493
                whitelist.insert(child->object_path, false);
494
494
            }
495
495
        }
496
496
 
507
507
    whitelist.insert(opath,check);
508
508
}
509
509
 
510
 
// temporary helper
511
 
void GuiEngine::dump_whitelist_selection(void)
512
 
{
513
 
    // loop around all the children
514
 
    QMap<QDBusObjectPath,bool>::const_iterator iter = whitelist.begin();
515
 
 
516
 
    while(iter != whitelist.end() ) {
517
 
 
518
 
        bool yes = iter.value();
519
 
 
520
 
        qDebug() << iter.key().path() << (yes ? "Yes" : "No");
521
 
 
522
 
        iter++;
523
 
    }
524
 
}
525
 
 
526
510
void GuiEngine::Pause(void)
527
511
{
528
512
    // Very simple
581
565
    * and hopefully it is similar when we get it back from SessionStateRunList()
582
566
    */
583
567
    QList<QDBusObjectPath> temp_desired_job_list = \
584
 
            JobTreeNode::FilteredJobs(m_final_run_list,m_desired_job_list);
 
568
            JobTreeNode::FilteredJobs(m_desired_job_list,m_final_run_list);
585
569
 
586
570
    QStringList errors = UpdateDesiredJobList(m_session, temp_desired_job_list);
587
571
    if (errors.count() != 0) {
719
703
                     "JobResultAvailable",\
720
704
                     this,\
721
705
                     SLOT(CatchallLocalJobResultAvailableSignalsHandler(QDBusMessage)))) {
722
 
 
723
706
        qDebug("Failed to connect slot for JobResultAvailable events");
724
707
    }
725
708
 
726
709
    // to get only the *jobs* that are designated by the whitelist.
727
 
    m_desired_job_list = GenerateDesiredJobList(m_job_list);
 
710
    m_desired_job_list = GenerateDesiredJobList();
728
711
 
729
712
    // This is just the list of all provider jobs marked "local"
730
 
    m_local_job_list = GetLocalJobs();
731
 
 
732
 
    // desired local jobs are the Union of all local jobs and the desired jobs
733
 
    m_desired_local_job_list = JobTreeNode::FilteredJobs(m_local_job_list, \
734
 
                                                         m_desired_job_list);
 
713
    m_local_job_list = GetLocalJobs(m_desired_job_list);
735
714
 
736
715
    // Now I update the desired job list.
737
716
    QStringList errors = UpdateDesiredJobList(m_session, \
738
 
                                              m_desired_local_job_list);
 
717
                                              m_local_job_list);
739
718
    if (errors.count() != 0) {
740
719
        qDebug("UpdateDesiredJobList generated errors:");
741
720
 
975
954
                            m_submitted ? PB_FLAG_SUBMITTED: PB_FLAG_INCOMPLETE,\
976
955
                            current_job_id,
977
956
                            GUI_ENGINE_NAME_STR,
978
 
                            jsd.toJson());
 
957
                            jsd.toJson(),
 
958
                            "com.canonical.checkbox-gui");
979
959
 
980
960
    // Plainbox should save this session
981
961
    SessionPersistentSave(m_session);
1044
1024
                                        const QString &flags, \
1045
1025
                                        const QString &running_job_name, \
1046
1026
                                        const QString &title, \
1047
 
                                        const QByteArray& app_blob)
 
1027
                                        const QByteArray& app_blob, \
 
1028
                                        const QString &app_id)
1048
1029
{
1049
1030
    qDebug() << "GuiEngine::SetSessionStateMetadata() \n" \
1050
1031
             << " " << session.path() \
1051
1032
             << "\nflags           : " << flags \
1052
1033
             << "\nrunning_job_name: " << running_job_name \
1053
1034
             << "\ntitle           : " << title \
1054
 
             << "\napp_blob        : " << app_blob;
 
1035
             << "\napp_blob        : " << app_blob \
 
1036
             << "\napp_id          : " << app_id;
1055
1037
 
1056
1038
    QMap<QString,QVariant> metadata;
1057
1039
 
1068
1050
    metadata.insert("running_job_name",running_job_name);
1069
1051
    metadata.insert("title",title);
1070
1052
    metadata.insert("app_blob",app_blob);
 
1053
    metadata.insert("app_id",app_id);
1071
1054
 
1072
1055
    QDBusInterface iface(PBBusName, \
1073
1056
                         session.path(), \
1255
1238
    return session;
1256
1239
}
1257
1240
 
1258
 
QList<QDBusObjectPath> GuiEngine::GetLocalJobs(void)
 
1241
QList<QDBusObjectPath> GuiEngine::GetLocalJobs(const QList<QDBusObjectPath> &job_list)
1259
1242
{
1260
1243
    QList<QDBusObjectPath> generator_jobs;
1261
1244
 
1262
 
    QList<PBTreeNode*> jobnodes = GetJobNodes();
1263
 
 
1264
 
    QList<PBTreeNode*>::const_iterator iter = jobnodes.begin();
1265
 
 
1266
 
    while(iter != jobnodes.end()) {
1267
 
 
1268
 
        PBTreeNode* node = *iter;
1269
 
 
1270
 
        QList<PBObjectInterface*> interfaces = node->interfaces;
1271
 
 
1272
 
        // Now find the plainbox interface
1273
 
        for (int i=0; i< interfaces.count(); i++) {
1274
 
            if (interfaces.at(i)->interface.compare(CheckBoxJobDefinition1) == 0) {
1275
 
 
1276
 
                // Now we need to find the plugin property
1277
 
                QVariant variant;
1278
 
 
1279
 
                variant = interfaces.at(i)->properties.find("plugin").value();
1280
 
 
1281
 
                if (variant.isValid() && variant.canConvert(QMetaType::QString)) {
1282
 
                    if (variant.toString().compare("local") == 0) {
1283
 
 
1284
 
                        // now append this to the list of jobs for CreateSession()
1285
 
                        generator_jobs.append(node->object_path);
1286
 
                    }
1287
 
                }
1288
 
            }
1289
 
        }
1290
 
 
1291
 
        iter++;
 
1245
    QListIterator<QDBusObjectPath> jobs(job_list);
 
1246
    while (jobs.hasNext()) {
 
1247
        QDBusObjectPath job = jobs.next();
 
1248
        QDBusInterface job_iface(PBBusName, \
 
1249
                           job.path(), \
 
1250
                           CheckBoxJobDefinition1, \
 
1251
                           QDBusConnection::sessionBus());
 
1252
        if (!job_iface.isValid()) {
 
1253
            throw std::runtime_error("Could not connect to com.canonical.certification.CheckBox.JobDefinition1 interface");
 
1254
        }
 
1255
        if (job_iface.property("plugin").toString() == "local") {
 
1256
            generator_jobs.append(job);
 
1257
            qDebug() << job.path();
 
1258
        }
1292
1259
    }
1293
1260
 
1294
1261
    return generator_jobs;
1681
1648
}
1682
1649
 
1683
1650
 
1684
 
QList<QDBusObjectPath> GuiEngine::GenerateDesiredJobList(QList<QDBusObjectPath> job_list)
 
1651
QList<QDBusObjectPath> GuiEngine::GenerateDesiredJobList()
1685
1652
{
1686
1653
    QList<QDBusObjectPath> desired_job_list;
1687
1654
 
1688
 
    // Iterate through each whitelist, and check if it Designates each job
 
1655
    QDBusInterface iface(PBBusName, \
 
1656
                         PBObjectPathName, \
 
1657
                         PBInterfaceName, \
 
1658
                         QDBusConnection::sessionBus());
 
1659
    if (!iface.isValid()) {
 
1660
        qDebug("Could not connect to \
 
1661
               com.canonical.certification.PlainBox.Service1 interface");
 
1662
        return desired_job_list;
 
1663
    }
 
1664
 
 
1665
    QList<QDBusObjectPath> whitelists;
1689
1666
    QMap<QDBusObjectPath, bool>::iterator iter = whitelist.begin();
1690
 
    while(iter != whitelist.end()) {
1691
 
 
1692
 
        // Try it if we have selected this whitelist
 
1667
    while (iter != whitelist.end()) {
1693
1668
        if (iter.value()) {
1694
 
            QDBusObjectPath white = iter.key();
1695
 
 
1696
 
            // local_jobs
1697
 
            for(int i=0; i < job_list.count(); i++) {
1698
 
 
1699
 
                QDBusObjectPath job = job_list.at(i);
1700
 
 
1701
 
                // Does the whitelist designate this job?
1702
 
                bool ok = WhiteListDesignates(white,job);
1703
 
 
1704
 
                // If ANY whitelist wants this job, we say yes
1705
 
                if (ok) {
1706
 
                    if (!desired_job_list.contains(job)) {
1707
 
                        desired_job_list.append(job);
1708
 
                    }
1709
 
                }
1710
 
            }
 
1669
            whitelists.append(iter.key());
1711
1670
        }
1712
 
 
1713
 
        // Next whitelist
1714
1671
        iter++;
1715
1672
    }
1716
1673
 
 
1674
    QDBusReply<opath_array_t> reply = \
 
1675
            iface.call("SelectJobs", \
 
1676
                       QVariant::fromValue<opath_array_t>(whitelists));
 
1677
 
 
1678
    if (reply.isValid()) {
 
1679
        desired_job_list = reply.value();
 
1680
    } else {
 
1681
        qDebug("Failed to CreateSession()");
 
1682
    }
1717
1683
    return desired_job_list;
1718
1684
}
1719
1685
 
2116
2082
    return reply;
2117
2083
}
2118
2084
 
 
2085
QString GuiEngine::SendDataViaTransport(const QDBusObjectPath session, \
 
2086
                                        const QString &transport, \
 
2087
                                        const QString &url, \
 
2088
                                        const QString &option_list, \
 
2089
                                        const QString &data)
 
2090
{
 
2091
    QDBusInterface iface(PBBusName, \
 
2092
                         PBObjectPathName, \
 
2093
                         PBInterfaceName, \
 
2094
                         QDBusConnection::sessionBus());
 
2095
    if (!iface.isValid()) {
 
2096
        qDebug() << "Could not connect to " << PBInterfaceName;
 
2097
        return QString("Could not connect to " + PBInterfaceName);
 
2098
    }
 
2099
 
 
2100
    QDBusReply<QString> reply = \
 
2101
            iface.call("SendDataViaTransport", \
 
2102
                       QVariant::fromValue<QString>(session.path()), \
 
2103
                       QVariant::fromValue<QString>(transport), \
 
2104
                       QVariant::fromValue<QString>(url), \
 
2105
                       QVariant::fromValue<QString>(option_list), \
 
2106
                       QVariant::fromValue<QString>(data));
 
2107
    if (!reply.isValid()) {
 
2108
        qDebug() << "Error: " << reply.error();
 
2109
        return QString("Error: " + reply.error().message());
 
2110
    }
 
2111
    return reply;                          
 
2112
}
 
2113
 
 
2114
const QString GuiEngine::SendSubmissionViaCertificationTransport( \
 
2115
        const QString &submission_path,
 
2116
        const QString &secure_id,
 
2117
        const bool submit_to_hexr)
 
2118
{
 
2119
    QDBusInterface iface(PBBusName, \
 
2120
                         PBObjectPathName, \
 
2121
                         PBInterfaceName, \
 
2122
                         QDBusConnection::sessionBus());
 
2123
    if (!iface.isValid()) {
 
2124
        qDebug() << "Could not connect to " << PBInterfaceName;
 
2125
        return QString("Could not connect to " + PBInterfaceName);
 
2126
    }
 
2127
 
 
2128
 
 
2129
    QDBusReply<QStringList> reply = iface.call("GetAllTransports");
 
2130
    if (!reply.isValid()) {
 
2131
        qDebug() << "Error: " << reply.error();
 
2132
        return QString("Error: " + reply.error().message());
 
2133
    }
 
2134
    if (!reply.value().contains("certification")) {
 
2135
        return QString("'certification' is not a supported transport");
 
2136
    }
 
2137
 
 
2138
    // Read submission file
 
2139
    QFile submissionFile(submission_path);
 
2140
    QByteArray submissionData;
 
2141
    if (submissionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
 
2142
        submissionData = submissionFile.readAll();
 
2143
        submissionFile.close();
 
2144
    }
 
2145
    else {
 
2146
        qDebug() << "Could not read " << submission_path;
 
2147
        return QString("Could not read " + submission_path);
 
2148
    }
 
2149
 
 
2150
    QStringList options;
 
2151
    options << QString("secure_id=" + secure_id);
 
2152
    options << QString("submit_to_hexr=" + QString::number(submit_to_hexr));
 
2153
 
 
2154
    return SendDataViaTransport(m_session, "certification", \
 
2155
            "https://certification.canonical.com/submissions/submit/", \
 
2156
            options.join(','), \
 
2157
            submissionData);
 
2158
}
 
2159
 
 
2160
const QString GuiEngine::SendSubmissionViaLaunchpadTransport( \
 
2161
        const QString &submission_path,
 
2162
        const QString &email)
 
2163
{
 
2164
    QDBusInterface iface(PBBusName, \
 
2165
                         PBObjectPathName, \
 
2166
                         PBInterfaceName, \
 
2167
                         QDBusConnection::sessionBus());
 
2168
    if (!iface.isValid()) {
 
2169
        qDebug() << "Could not connect to " << PBInterfaceName;
 
2170
        return QString("Could not connect to " + PBInterfaceName);
 
2171
    }
 
2172
 
 
2173
 
 
2174
    QDBusReply<QStringList> reply = iface.call("GetAllTransports");
 
2175
    if (!reply.isValid()) {
 
2176
        qDebug() << "Error: " << reply.error();
 
2177
        return QString("Error: " + reply.error().message());
 
2178
    }
 
2179
    if (!reply.value().contains("launchpad")) {
 
2180
        return QString("'launchpad' is not a supported transport");
 
2181
    }
 
2182
 
 
2183
    // Read submission file
 
2184
    QFile submissionFile(submission_path);
 
2185
    QByteArray submissionData;
 
2186
    if (submissionFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
 
2187
        submissionData = submissionFile.readAll();
 
2188
        submissionFile.close();
 
2189
    }
 
2190
    else {
 
2191
        qDebug() << "Could not read " << submission_path;
 
2192
        return QString("Could not read " + submission_path);
 
2193
    }
 
2194
 
 
2195
    QStringList options;
 
2196
    options << QString("field.emailaddress=" + email);
 
2197
 
 
2198
    return SendDataViaTransport(m_session, "launchpad", \
 
2199
            "https://launchpad.net/+hwdb/+submit", \
 
2200
            options.join(','), \
 
2201
            submissionData);
 
2202
}
 
2203
 
2119
2204
void GuiEngine::CatchallIOLogGeneratedSignalsHandler(QDBusMessage /*msg*/)
2120
2205
{
2121
2206
    /* TODO - This could be used for updating a live display of the IO Log
2188
2273
        return;
2189
2274
    }
2190
2275
 
2191
 
    // get the job-list: NB: From the SessionState this time
2192
 
    m_job_list = SessionStateJobList(m_session);
2193
 
 
2194
2276
    // to get only the *jobs* that are designated by the whitelist.
2195
 
    m_desired_job_list = GenerateDesiredJobList(m_job_list);
 
2277
    m_desired_job_list = GenerateDesiredJobList();
2196
2278
 
2197
2279
    /* Now I update the desired job list.
2198
2280
        XXX: Remove previous local jobs from this list to avoid evaluating
2209
2291
 
2210
2292
    // Now, the run_list contains the list of jobs I actually need to run \o/
2211
2293
    m_run_list = SessionStateRunList(m_session);
 
2294
    QListIterator<QDBusObjectPath> run_jobs(m_run_list);
2212
2295
 
2213
2296
    // Keep a copy of what should be visible
2214
2297
    m_visible_run_list = m_run_list;