Add "freely accessable for everybody" checkbox to the publish page in

the applet config.

svn path=/trunk/KDE/kdelibs/; revision=1019593
This commit is contained in:
Rob Scheepmaker 2009-09-04 00:08:26 +00:00
parent fb14be1caa
commit c69e570b68
6 changed files with 55 additions and 12 deletions

View File

@ -64,6 +64,7 @@
#include <solid/powermanagement.h>
#include "authorizationmanager.h"
#include "authorizationrule.h"
#include "configloader.h"
#include "containment.h"
#include "corona.h"
@ -1454,7 +1455,7 @@ bool Applet::hasConfigurationInterface() const
return d->hasConfigurationInterface;
}
void Applet::publish(AnnouncementMethods methods)
void Applet::publish(AnnouncementMethods methods, const QString &resourceName)
{
if (d->package) {
d->package->d->publish(methods);
@ -1463,9 +1464,6 @@ void Applet::publish(AnnouncementMethods methods)
d->service = new PlasmoidService(this);
}
QString resourceName =
i18nc("%1 is the name of a plasmoid, %2 the name of the machine that plasmoid is published on",
"%1 on %2", name(), QHostInfo::localHostName());
kDebug() << "publishing package under name " << resourceName;
d->service->d->publish(methods, resourceName);
}
@ -1748,10 +1746,32 @@ void AppletPrivate::addPublishPage(KConfigDialog *dialog)
{
QWidget *page = new QWidget;
publishUI.setupUi(page);
publishUI.publishCheckbox->setChecked(q->config().readEntry("Publish", false));
publishUI.publishCheckbox->setChecked(q->isPublished());
publishUI.allUsersCheckbox->setEnabled(q->isPublished());
QString resourceName =
i18nc("%1 is the name of a plasmoid, %2 the name of the machine that plasmoid is published on",
"%1 on %2", q->name(), QHostInfo::localHostName());
if (AuthorizationManager::self()->d->matchingRule(resourceName, Credentials())) {
publishUI.allUsersCheckbox->setChecked(true);
} else {
publishUI.allUsersCheckbox->setChecked(false);
}
q->connect(publishUI.publishCheckbox, SIGNAL(stateChanged(int)),
q, SLOT(publishCheckboxStateChanged(int)));
dialog->addPage(page, i18n("Publish"), "applications-internet");
}
void AppletPrivate::publishCheckboxStateChanged(int state)
{
if (state == Qt::Checked) {
publishUI.allUsersCheckbox->setEnabled(true);
} else {
publishUI.allUsersCheckbox->setEnabled(false);
}
}
void AppletPrivate::clearShortcutEditorPtr()
{
shortcutEditor = 0;
@ -1770,7 +1790,24 @@ void AppletPrivate::configDialogFinished()
q->config().writeEntry("Publish", publishUI.publishCheckbox->isChecked());
if (publishUI.publishCheckbox->isChecked()) {
q->publish(Plasma::ZeroconfAnnouncement);
QString resourceName =
i18nc("%1 is the name of a plasmoid, %2 the name of the machine that plasmoid is published on",
"%1 on %2", q->name(), QHostInfo::localHostName());
q->publish(Plasma::ZeroconfAnnouncement, resourceName);
if (publishUI.allUsersCheckbox->isChecked()) {
if (!AuthorizationManager::self()->d->matchingRule(resourceName, Credentials())) {
AuthorizationRule *rule = new AuthorizationRule(resourceName, "");
rule->setPolicy(AuthorizationRule::Allow);
rule->setTargets(AuthorizationRule::AllUsers);
AuthorizationManager::self()->d->rules.append(rule);
}
} else {
AuthorizationRule *matchingRule =
AuthorizationManager::self()->d->matchingRule(resourceName, Credentials());
if (matchingRule) {
AuthorizationManager::self()->d->rules.removeAll(matchingRule);
}
}
} else {
q->unpublish();
}
@ -2406,11 +2443,6 @@ void AppletPrivate::init(const QString &packagePath)
configAction->setText(i18nc("%1 is the name of the applet", "%1 Settings", q->name()));
}
if (q->config().readEntry("Publish", false)) {
kDebug() << "according the the config, this applet is published, so publish it now!";
q->publish(Plasma::ZeroconfAnnouncement);
}
QObject::connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()));
QObject::connect(q, SIGNAL(activate()), q, SLOT(setFocus()));
}

View File

@ -788,7 +788,13 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
void setStatus(const ItemStatus stat);
void publish(Plasma::AnnouncementMethods method);
/**
* Publishes and optionally announces this applet on the network for remote access.
* @param methods the methods to use for announcing this applet.
* @param resourceName the name under which this applet will be published (has to be unique
* for each machine)
*/
void publish(Plasma::AnnouncementMethods methods, const QString &resourceName);
void unpublish();
@ -992,6 +998,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
Q_PRIVATE_SLOT(d, void clearShortcutEditorPtr())
Q_PRIVATE_SLOT(d, void configDialogFinished())
Q_PRIVATE_SLOT(d, void updateShortcuts())
Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state))
/**
* Reimplemented from QGraphicsItem

View File

@ -99,6 +99,7 @@ public:
QString configDialogId() const;
QString configWindowTitle() const;
void updateShortcuts();
void publishCheckboxStateChanged(int state);
static KActionCollection* defaultActions(QObject *parent);
static QSet<QString> knownCategories();

View File

@ -56,6 +56,7 @@ void GetSource::start()
service->d->publish(Plasma::NoAnnouncement, serviceName);
if (!AuthorizationManager::self()->d->matchingRule(serviceName, identity())) {
AuthorizationRule *rule = new AuthorizationRule(serviceName, identity().id());
rule->setPolicy(AuthorizationRule::Allow);
AuthorizationManager::self()->d->rules.append(rule);
}
setResult(serviceName);

View File

@ -108,6 +108,7 @@ class PLASMA_EXPORT AuthorizationManager : public QObject
friend class AuthorizationRule;
friend class AuthorizationRulePrivate;
friend class Applet;
friend class AppletPrivate;
friend class Credentials;
friend class DataEngine;
friend class GetSource;

View File

@ -155,6 +155,7 @@ class PLASMA_EXPORT AuthorizationRule : public QObject
Q_PRIVATE_SLOT(d, void fireChangedSignal())
friend class AppletPrivate;
friend class AuthorizationManager;
friend class AuthorizationManagerPrivate;
friend class AuthorizationRulePrivate;