Development/Tutorials/Collaboration/HotNewStuff/Updates: Difference between revisions

From KDE TechBase
(Mark for updating)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Template:I18n/Language Navigation Bar|Development/Tutorials/Collaboration/HotNewStuff/Updates}}
 


{{TutorialBrowser|
{{TutorialBrowser|
Line 6: Line 6:
pre=[[Development/Tutorials/Collaboration/HotNewStuff/Introduction|Get Hot New Stuff 3 - Download]]|
pre=[[Development/Tutorials/Collaboration/HotNewStuff/Introduction|Get Hot New Stuff 3 - Download]]|
next=[[Development/Tutorials/Collaboration/HotNewStuff/Upload|Get Hot New Stuff 3 - Upload]]|
next=[[Development/Tutorials/Collaboration/HotNewStuff/Upload|Get Hot New Stuff 3 - Upload]]|
reading=[http://api.kde.org/4.x-api/kdelibs-apidocs/knewstuff/html/classKNS3_1_1DownloadManager.html API Documentation]
}}  
}}  
{{Review|Port to KF5}}


== Overview  ==
== Overview  ==
Line 17: Line 20:


Use an instance of DownloadManager in your class:
Use an instance of DownloadManager in your class:
<code cppqt="cppqt">
<syntaxhighlight lang="cpp-qt">
    m_downloadManager = new KNS3::DownloadManager("plasmoids.knsrc", this);
m_downloadManager = new KNS3::DownloadManager("plasmoids.knsrc", this);
    // to know when checking for updates is done
 
    connect(m_downloadManager, SIGNAL(searchResult(KNS3::Entry::List)),  
// to know when checking for updates is done
        this, SLOT(slotUpdatesFound(KNS3::Entry::List)));
connect(m_downloadManager, SIGNAL(searchResult(KNS3::Entry::List)),  
    // to know about finished installations
    this, SLOT(slotUpdatesFound(KNS3::Entry::List)));
    connect(m_downloadManager, SIGNAL(entryStatusChanged(KNS3::Entry)),  
 
        this, SLOT(entryStatusChanged(KNS3::Entry)));
// to know about finished installations
    m_downloadManager->checkForUpdates();
connect(m_downloadManager, SIGNAL(entryStatusChanged(KNS3::Entry)),  
</code>
    this, SLOT(entryStatusChanged(KNS3::Entry)));
 
// start checking for updates
m_downloadManager->checkForUpdates();
</syntaxhighlight>


The entryStatusChanged signal informs you when you installed an entry. If you don't want to make use of that possibility, you can ignore the signal.
The entryStatusChanged signal informs you when you installed an entry. If you don't want to make use of that possibility, you can ignore the signal.
<code cppqt="cppqt">
<syntaxhighlight lang="cpp-qt">
void UpdateChecker::slotUpdatesFound(const KNS3::Entry::List& updates)
void UpdateChecker::slotUpdatesFound(const KNS3::Entry::List& updates)
{
{
     m_updates = updates;
     m_updates = updates;
     foreach (const KNS3::Entry& entry, updates) {
     foreach (const KNS3::Entry& entry, updates) {
         kDebug() << entry.name();
         qDebug() << entry.name();
     }
     }
}</code>
}</syntaxhighlight>
To install an entry you can show the download dialog or do it without the dialog by using:
To install an entry you can '''show the download dialog''' or do it without the dialog by using:
<code cppqt="cppqt">
<syntaxhighlight lang="cpp-qt">
m_downloadManager->installEntry(entry);
m_downloadManager->installEntry(entry);
</code>
</syntaxhighlight>

Latest revision as of 12:50, 31 May 2019


Get Hot New Stuff 3 Introduction
Tutorial Series   HotNewStuff
Previous   Get Hot New Stuff 3 - Download
What's Next   Get Hot New Stuff 3 - Upload
Further Reading   API Documentation
Warning
This page needs a review and probably holds information that needs to be fixed.

Parts to be reviewed:

Port to KF5

Overview

Just like firefox informs you of updates to your addons, KNewStuff can let you check for updates since KDE SC 4.5.

There is an example in kdeexamples.

DownloadManager

The class in question is DownloadManager.

Use an instance of DownloadManager in your class:

m_downloadManager = new KNS3::DownloadManager("plasmoids.knsrc", this);

// to know when checking for updates is done
connect(m_downloadManager, SIGNAL(searchResult(KNS3::Entry::List)), 
    this, SLOT(slotUpdatesFound(KNS3::Entry::List)));

// to know about finished installations
connect(m_downloadManager, SIGNAL(entryStatusChanged(KNS3::Entry)), 
    this, SLOT(entryStatusChanged(KNS3::Entry)));

// start checking for updates
m_downloadManager->checkForUpdates();

The entryStatusChanged signal informs you when you installed an entry. If you don't want to make use of that possibility, you can ignore the signal.

void UpdateChecker::slotUpdatesFound(const KNS3::Entry::List& updates)
{
    m_updates = updates;
    foreach (const KNS3::Entry& entry, updates) {
        qDebug() << entry.name();
    }
}

To install an entry you can show the download dialog or do it without the dialog by using:

m_downloadManager->installEntry(entry);