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

From KDE TechBase
No edit summary
(→‎The Configuration File (.knsrc): Add comment to suggest using the default value for ProvidersUrl rather than an explicit one)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Template:I18n/Language Navigation Bar|Development/Tutorials/Collaboration/HotNewStuff/Upload}}


{{TutorialBrowser|
{{TutorialBrowser|
Line 5: Line 4:
name=Get Hot New Stuff 3 - Upload|
name=Get Hot New Stuff 3 - Upload|
pre=[[Development/Tutorials/Collaboration/HotNewStuff/Updates|Get Hot New Stuff 3 - Updates]]|
pre=[[Development/Tutorials/Collaboration/HotNewStuff/Updates|Get Hot New Stuff 3 - Updates]]|
reading=[http://api.kde.org/4.x-api/kdelibs-apidocs/knewstuff/html/classKNS3_1_1UploadDialog.html API Documentation]
}}  
}}  
{{Improve}}


=== Overview  ===
=== Overview  ===
Line 14: Line 16:
==== The Code  ====
==== The Code  ====


<code  cppqt="cppqt">
<syntaxhighlight lang="cpp-qt">
#include <knewstuff3/uploaddialog.h>
#include <knewstuff3/uploaddialog.h>


Line 33: Line 35:
// show the dialog as modal (you can also use show of course)
// show the dialog as modal (you can also use show of course)
dialog.exec();
dialog.exec();
</code>
</syntaxhighlight>


==== The Configuration File (.knsrc)  ====
==== The Configuration File (.knsrc)  ====
In addition to the download version, you need to add UploadCategories, to set up where the contents can be uploaded to.
In addition to the download version, you need to add UploadCategories, to set up where the contents can be uploaded to.


<code>
<syntaxhighlight lang="text">
[KNewStuff3]
[KNewStuff3]
ProvidersUrl=http://download.kde.org/ocs/providers.xml
ProvidersUrl=http://autoconfig.kde.org/ocs/providers.xml
UploadCategories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200
UploadCategories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200
</code>  
</syntaxhighlight>
 
NB: If you are expecting to use the KDE Store, you do not need to add the ProvidersUrl entry, as this will default to the correct location for the KDE Store.


==== Linking in CMakeLists.txt ====
==== Linking in CMakeLists.txt ====
To link against KNS3, just link against ''${KDE4_KNEWSTUFF3_LIBS}''. Example:
To link against KNS3, just link against ''KF5::NewStuff''. Example:


<code>
<syntaxhighlight lang="text">
target_link_libraries(ktexteditor_codesnippets_core
target_link_libraries(ktexteditor_codesnippets_core Qt5::Widgets KF5::TextEditor KF5::NewStuff)
${KDE4_KDEUI_LIBS} ${KDE4_KTEXTEDITOR_LIBS} ${KDE4_KNEWSTUFF3_LIBS})
</syntaxhighlight>
</code>

Latest revision as of 12:05, 30 January 2020

Get Hot New Stuff 3 - Upload
Tutorial Series   HotNewStuff
Previous   Get Hot New Stuff 3 - Updates
What's Next   n/a
Further Reading   API Documentation
Warning
This section needs improvements: Please help us to

cleanup confusing sections and fix sections which contain a todo


Overview

Adding an upload dialog to an application is straight forward. If you already have a download dialog, you just need to add a few lines to the .knsrc file and create the dialog. Uploading currently only works with openDesktop.org and other websites that implement the Open Collaboration Services API.

The Code

#include <knewstuff3/uploaddialog.h>

// create the dialog
KNS3::UploadDialog dialog(parentWidget);

// set it up to help the user fill it out
// the file to be uploaded - this is important!
dialog.setUploadFile("some_url_here");

// a suggested title, the user can still change it
// don't set it if you can't make a reasonable suggestion
dialog.setUploadName("A suggested title for the upload");

// a longer description, optional
dialog.setDescription("This is a great file. It was created using foo.");

// show the dialog as modal (you can also use show of course)
dialog.exec();

The Configuration File (.knsrc)

In addition to the download version, you need to add UploadCategories, to set up where the contents can be uploaded to.

[KNewStuff3]
ProvidersUrl=http://autoconfig.kde.org/ocs/providers.xml
UploadCategories=KDE Wallpaper 1920x1200,KDE Wallpaper 1600x1200

NB: If you are expecting to use the KDE Store, you do not need to add the ProvidersUrl entry, as this will default to the correct location for the KDE Store.

Linking in CMakeLists.txt

To link against KNS3, just link against KF5::NewStuff. Example:

target_link_libraries(ktexteditor_codesnippets_core Qt5::Widgets KF5::TextEditor KF5::NewStuff)