[SCM] plasma-widget-fastuserswitch packaging branch, master, updated. 185059fbcc65a743a1b36e7ad2fbcf4dca03901e
Rohan Garg
rohangarg-guest at alioth.debian.org
Sun Jul 25 17:31:09 UTC 2010
The following commit has been merged in the master branch:
commit d2f191e923968fde9ca06be38acaf8b6bb960e95
Author: Rohan Garg <rohangarg at ubuntu.com>
Date: Sun Jul 25 23:00:43 2010 +0530
Imported Upstream version 0.2.1
---
CMakeLists.txt | 9 ++
ChangeLog | 10 ++
common.cpp | 31 ++++++
sessionwidget.h => common.h | 29 ++----
fastuserswitch.cpp | 191 ++++++++++++++++++++++++++++++----
fastuserswitch.h | 30 +++++-
fastuserswitchConfig.ui | 84 +++++++++++++++
plasma-applet-fastuserswitch.desktop | 4 +-
sessionwidget.cpp | 17 +--
9 files changed, 346 insertions(+), 59 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 73634b6..f5ea6a0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,11 +3,20 @@ project(plasma-fastuserswitch)
find_package(KDE4 REQUIRED)
include(KDE4Defaults)
+include_directories(
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_BINARY_DIR}
+ ${KDE4_INCLUDES}
+)
+
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
+include_directories(${KDE4_INCLUDES} ${QT_INCLUDES})
set(fastuserswitch_SRCS
+ common.cpp
fastuserswitch.cpp
sessionwidget.cpp)
+kde4_add_ui_files(fastuserswitch_SRCS fastuserswitchConfig.ui)
kde4_add_plugin(plasma_applet_fastuserswitch ${fastuserswitch_SRCS})
target_link_libraries(plasma_applet_fastuserswitch ${KDE4_PLASMA_LIBS} kworkspace)
diff --git a/ChangeLog b/ChangeLog
index 0b6c040..092b68e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Fri Jul 23 00:44:48 CEST 2010 Flavio Castelli <flavio at castelli.name>
+
+ * added new configurations:
+ - show only icon.
+ - show icon + name.
+ - show only name.
+ * it's possible to show user's avatar image instead of the default picture.
+ * it's possible to show user's complete name instead of his login name.
+ * fixed some build issues.
+
Wed Jul 14 13:42:46 CEST 2010 Flavio Castelli <flavio at castelli.name>
* added tooltip
diff --git a/common.cpp b/common.cpp
new file mode 100644
index 0000000..eff2a8e
--- /dev/null
+++ b/common.cpp
@@ -0,0 +1,31 @@
+#include "common.h"
+
+#include <QtCore/QFile>
+
+#include <kicon.h>
+#include <kiconloader.h>
+#include <kuser.h>
+
+const QString getUsername(bool useShortName, const KUser& user)
+{
+ if (useShortName)
+ return user.loginName();
+
+ QString username = user.property(KUser::FullName).toString();
+ if (username.isEmpty())
+ username = user.loginName();
+
+ return username;
+}
+
+QPixmap getUserIcon(const KUser& user)
+{
+ QPixmap pixmap;
+ int iconSize = IconSize(KIconLoader::Desktop);
+ if (QFile::exists(user.faceIconPath())) {
+ pixmap.load(user.faceIconPath());
+ } else
+ pixmap = KIcon(DEFAULT_ICON_NAME).pixmap(iconSize);
+
+ return pixmap;
+}
diff --git a/sessionwidget.h b/common.h
similarity index 77%
copy from sessionwidget.h
copy to common.h
index a148672..ddc9cd5 100644
--- a/sessionwidget.h
+++ b/common.h
@@ -17,30 +17,17 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
-#ifndef SESSIONWIDGET_H
-#define SESSIONWIDGET_H
+#ifndef COMMON_H
+#define COMMON_H
-#include <QtGui/QGraphicsWidget>
+#include <kuser.h>
-class QSignalMapper;
+#include <QtCore/QString>
+#include <QtGui/QPixmap>
-class SessionWidget :public QGraphicsWidget
-{
- Q_OBJECT
+static const char DEFAULT_ICON_NAME[] = "user-identity";
- public:
- SessionWidget ( QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0 );
-
- signals:
- void switching();
-
- private slots:
- void slotSwitchSession(int);
-
- private:
- void clearEntries();
-
- QSignalMapper* m_signalMapper;
-};
+const QString getUsername(bool useShortName=false, const KUser& user = KUser());
+QPixmap getUserIcon(const KUser& user = KUser());
#endif
diff --git a/fastuserswitch.cpp b/fastuserswitch.cpp
index b3e10c7..3048e98 100644
--- a/fastuserswitch.cpp
+++ b/fastuserswitch.cpp
@@ -17,33 +17,43 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
+#include "common.h"
#include "fastuserswitch.h"
#include "sessionwidget.h"
-#include <kicon.h>
+#include <QtGui/QGraphicsLinearLayout>
+#include <QtGui/QGraphicsSceneResizeEvent>
+#include <QtGui/QLabel>
+
#include <kiconloader.h>
-#include <kuser.h>
+#include <kconfigdialog.h>
+#include <ksharedconfig.h>
+
#include <plasma/extenderitem.h>
#include <plasma/tooltipcontent.h>
#include <plasma/tooltipmanager.h>
+#include <plasma/widgets/label.h>
using namespace Plasma;
-static const char DEFAULT_ICON_NAME[] = "system-switch-user";
-
K_EXPORT_PLASMA_APPLET(fastuserswitch, FastUserSwitch)
+#define ICON_PLUS_TEXT "showIconPlusText"
+#define ICON_ONLY "showOnlyIcon"
+#define TEXT_ONLY "showOnlyText"
+#define USE_USER_IMAGE "useUserImage"
+#define USE_COMPLETE_NAME "useCompleteName"
+
+#define MARGINSIZE 6
+
FastUserSwitch::FastUserSwitch(QObject *parent, const QVariantList &args)
: Plasma::PopupApplet(parent, args),
- m_dialog(0)
+ m_dialog(0),
+ m_labelIcon(0)
{
- setPopupIcon(QIcon());
- int iconSize = IconSize(KIconLoader::Desktop);
- resize(iconSize*2 , iconSize*2 );
- setAspectRatioMode(Plasma::ConstrainedSquare );
- setPopupIcon(QIcon());
- //we load some icon
- m_icon= new KIcon(DEFAULT_ICON_NAME);
+ setAspectRatioMode(Plasma::IgnoreAspectRatio);
+ setHasConfigurationInterface(true);
+
//create extender
m_extender = new Plasma::ExtenderItem(extender());
m_extender->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
@@ -52,24 +62,50 @@ FastUserSwitch::FastUserSwitch(QObject *parent, const QVariantList &args)
FastUserSwitch::~FastUserSwitch()
{
- delete m_icon;
}
void FastUserSwitch::init()
{
- setHasConfigurationInterface(false);
- setPopupIcon(DEFAULT_ICON_NAME);
+ configChanged();
+
+ QString username = getUsername(!m_useCompleteName);
+ m_userpixmap = getUserIcon();
+
+ m_layout = new QGraphicsLinearLayout(Qt::Horizontal, this);
+ m_layout->setSpacing(0);
+
+ m_labelIcon = new Plasma::Label();
+ m_labelIcon->nativeWidget()->setSizePolicy(QSizePolicy::Preferred,
+ QSizePolicy::Preferred);
+
+ m_labelName = new Plasma::Label();
+ m_labelName->setAlignment(Qt::AlignCenter);
+ m_labelName->nativeWidget()->setMargin(10);
+ m_labelName->nativeWidget()->setSizePolicy(QSizePolicy::MinimumExpanding,
+ QSizePolicy::MinimumExpanding);
+
+ setLayout(m_layout);
+
+ checkLayout();
+ setupTooltip();
+}
+
+void FastUserSwitch::setupTooltip()
+{
+ QString username = getUsername(!m_useCompleteName);
+ QPixmap pixmap;
- //init tooltip
- KUser user;
- QString username = user.property(KUser::FullName).toString();
- if (username.isEmpty())
- username = user.loginName();
+ if (m_useUserImage) {
+ pixmap = m_userpixmap.scaledToHeight(qMin(IconSize(KIconLoader::Desktop),
+ m_userpixmap.height()));
+ } else
+ pixmap = KIcon(DEFAULT_ICON_NAME).pixmap(IconSize(KIconLoader::Desktop));
Plasma::ToolTipContent data;
data.setMainText(i18n("Fast user switch"));
- data.setSubText(i18n("You are currently logged in as %1", username));
- data.setImage(KIcon(DEFAULT_ICON_NAME).pixmap(IconSize(KIconLoader::Desktop)));
+ data.setSubText(i18n("You are currently logged in as <em>%1</em>.",
+ username));
+ data.setImage(pixmap);
Plasma::ToolTipManager::self()->setContent(this, data);
}
@@ -81,7 +117,116 @@ void FastUserSwitch::initExtenderItem(Plasma::ExtenderItem *item)
m_dialog = new SessionWidget(item);
connect(m_dialog, SIGNAL(switching()), this, SLOT(hidePopup()));
item->setWidget(m_dialog);
- item->setTitle(i18n("Switch User"));
+ item->setTitle(i18n("Fast user switch"));
+}
+
+void FastUserSwitch::configChanged()
+{
+ KConfigGroup cg = config();
+ m_showIconPlusText = cg.readEntry(ICON_PLUS_TEXT, false);
+ m_showOnlyIcon = cg.readEntry(ICON_ONLY, true);
+ m_showOnlyText = cg.readEntry(TEXT_ONLY, false);
+ m_useUserImage = cg.readEntry(USE_USER_IMAGE, false);
+ m_useCompleteName = cg.readEntry(USE_COMPLETE_NAME, true);
+}
+void FastUserSwitch::configAccepted()
+{
+ bool changed = false;
+ KConfigGroup cg = config();
+
+ if (m_showIconPlusText != ui.radioButton_iconPlusText->isChecked()) {
+ m_showIconPlusText = !m_showIconPlusText;
+ cg.writeEntry(ICON_PLUS_TEXT, m_showIconPlusText);
+ changed = true;
+ }
+
+ if (m_showOnlyIcon != ui.radioButton_iconOnly->isChecked()) {
+ m_showOnlyIcon = !m_showOnlyIcon;
+ cg.writeEntry(ICON_ONLY, m_showOnlyIcon);
+ changed = true;
+ }
+
+ if (m_showOnlyText != ui.radioButton_textOnly ->isChecked()) {
+ m_showOnlyText = !m_showOnlyText;
+ cg.writeEntry(TEXT_ONLY, m_showOnlyText);
+ changed = true;
+ }
+
+ if (m_useCompleteName != ui.checkBox_completeName->isChecked()) {
+ m_useCompleteName = !m_useCompleteName;
+ cg.writeEntry(USE_COMPLETE_NAME, m_useCompleteName);
+ changed = true;
+ }
+
+ if (m_useUserImage != ui.checkBox_userImage->isChecked()) {
+ m_useUserImage = !m_useUserImage;
+ cg.writeEntry(USE_USER_IMAGE, m_useUserImage);
+ changed = true;
+ }
+
+ if (changed) {
+ checkLayout();
+ setupTooltip();
+ emit configNeedsSaving();
+ }
+}
+
+void FastUserSwitch::createConfigurationInterface(KConfigDialog *parent)
+{
+ QWidget *widget = new QWidget(parent);
+ ui.setupUi(widget);
+ parent->addPage(widget, i18n("General"), Applet::icon());
+ connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
+ connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
+
+ ui.radioButton_iconPlusText->setChecked(m_showIconPlusText);
+ ui.radioButton_iconOnly->setChecked(m_showOnlyIcon);
+ ui.radioButton_textOnly->setChecked(m_showOnlyText);
+ ui.checkBox_completeName->setChecked(m_useCompleteName);
+ ui.checkBox_userImage->setChecked(m_useUserImage);
+}
+
+void FastUserSwitch::checkLayout()
+{
+ if ((!m_labelIcon) || (!m_labelName))
+ return;
+
+ int currentHeight = geometry().height() - MARGINSIZE;
+
+ m_layout->removeItem(m_labelIcon);
+ m_layout->removeItem(m_labelName);
+
+ m_labelIcon->setVisible(m_showOnlyIcon || m_showIconPlusText);
+ m_labelName->setVisible(m_showOnlyText || m_showIconPlusText);
+
+ if ((!m_showOnlyIcon) || m_showIconPlusText)
+ m_layout->addItem(m_labelName);
+
+ if ((!m_showOnlyText) || m_showIconPlusText) {
+ QPixmap pixmap;
+ if (m_useUserImage) {
+ pixmap = m_userpixmap.scaledToHeight(qMin(m_userpixmap.height(),
+ currentHeight));
+ } else {
+ pixmap = KIcon(DEFAULT_ICON_NAME).pixmap(qMin(IconSize(KIconLoader::Desktop),
+ currentHeight));
+ }
+
+ m_labelIcon->nativeWidget()->setPixmap(pixmap);
+ m_labelIcon->setPreferredSize(pixmap.width(), pixmap.height());
+ m_labelIcon->setMaximumSize(pixmap.width(), pixmap.height());
+ m_layout->addItem(m_labelIcon);
+ }
+
+ m_labelName->setText(QString("<strong>%1</strong>").arg(getUsername(!m_useCompleteName)));
+}
+
+void FastUserSwitch::constraintsEvent(Plasma::Constraints constraints)
+{
+ if (constraints & Plasma::FormFactorConstraint ||
+ constraints & Plasma::SizeConstraint) {
+ checkLayout();
+ }
}
void FastUserSwitch::popupEvent(bool show)
diff --git a/fastuserswitch.h b/fastuserswitch.h
index 6e272f7..2d1efda 100644
--- a/fastuserswitch.h
+++ b/fastuserswitch.h
@@ -23,11 +23,16 @@
//Plasma
#include <plasma/popupapplet.h>
+#include "ui_fastuserswitchConfig.h"
+
+class QGraphicsLinearLayout;
+
namespace Plasma {
class ExtenderItem;
+ class Label;
}
-class KIcon;
+class KConfigDialog;
class SessionWidget;
/**
@@ -51,16 +56,37 @@ class FastUserSwitch : public Plasma::PopupApplet
~FastUserSwitch();
void init();
+ virtual void constraintsEvent(Plasma::Constraints constraints);
+
+ public slots:
+ void configChanged();
+
+ protected Q_SLOTS:
+ void configAccepted();
protected:
+ void createConfigurationInterface(KConfigDialog *parent);
void popupEvent(bool show);
private:
void initExtenderItem(Plasma::ExtenderItem *item);
+ void checkLayout();
+ void setupTooltip();
+ QGraphicsLinearLayout* m_layout;
SessionWidget* m_dialog;
- KIcon* m_icon;
+ Plasma::Label* m_labelIcon;
+ Plasma::Label* m_labelName;
Plasma::ExtenderItem* m_extender;
+ QPixmap m_userpixmap;
+
+ bool m_showOnlyIcon;
+ bool m_showOnlyText;
+ bool m_showIconPlusText;
+ bool m_useCompleteName;
+ bool m_useUserImage;
+
+ Ui::FastuserswitchConfig ui;
};
#endif
diff --git a/fastuserswitchConfig.ui b/fastuserswitchConfig.ui
new file mode 100644
index 0000000..5058e25
--- /dev/null
+++ b/fastuserswitchConfig.ui
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FastuserswitchConfig</class>
+ <widget class="QWidget" name="FastuserswitchConfig">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>290</width>
+ <height>202</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Configure Lock/Logout</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Style</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QRadioButton" name="radioButton_iconOnly">
+ <property name="toolTip">
+ <string/>
+ </property>
+ <property name="text">
+ <string>Icon only</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButton_textOnly">
+ <property name="text">
+ <string>Text only</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButton_iconPlusText">
+ <property name="text">
+ <string>Icon plus text</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="checkBox_completeName">
+ <property name="text">
+ <string>Use user's complete name if set</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="checkBox_userImage">
+ <property name="text">
+ <string>Use user avatar if set</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/plasma-applet-fastuserswitch.desktop b/plasma-applet-fastuserswitch.desktop
index b886c5a..2d268db 100644
--- a/plasma-applet-fastuserswitch.desktop
+++ b/plasma-applet-fastuserswitch.desktop
@@ -7,7 +7,7 @@ Comment=Fast user switching applet
Comment[en_GB]=Fast user switching applet
Comment[it]=Applet per il cambio rapido di utente
Comment[x-test]=xxFast user switching appletxx
-Icon=system-switch-user
+Icon=user-identity
Type=Service
X-KDE-ServiceTypes=Plasma/Applet
@@ -15,7 +15,7 @@ X-KDE-Library=plasma_applet_fastuserswitch
X-KDE-PluginInfo-Author=Flavio Castelli
X-KDE-PluginInfo-Email=flavio at castelli.name
X-KDE-PluginInfo-Name=fastuserswitch
-X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-Version=0.2.1
X-KDE-PluginInfo-Website=http://flavio.castelli.name
X-KDE-PluginInfo-Category=System Information
X-KDE-PluginInfo-Depends=
diff --git a/sessionwidget.cpp b/sessionwidget.cpp
index 7a053c0..f89858d 100644
--- a/sessionwidget.cpp
+++ b/sessionwidget.cpp
@@ -18,8 +18,8 @@
***************************************************************************/
#include "sessionwidget.h"
+#include "common.h"
-#include <QtCore/QFile>
#include <QtCore/QList>
#include <QtCore/QSignalMapper>
#include <QtCore/QVariant>
@@ -28,7 +28,6 @@
#include <QtGui/QGraphicsLinearLayout>
#include <QtGui/QShowEvent>
-#include <kicon.h>
#include <kiconloader.h>
#include <kuser.h>
#include <kworkspace/kdisplaymanager.h>
@@ -81,19 +80,15 @@ SessionWidget::SessionWidget( QGraphicsItem * parent, Qt::WindowFlags wFlags)
if (!user.isValid())
continue;
- Plasma::IconWidget* entry = createButton(this);
+ if (session.tty)
+ continue;
- if (QFile::exists(user.faceIconPath())) {
- pixmap.load(user.faceIconPath());
- } else {
- pixmap = KIcon("preferences-desktop-user").pixmap(iconSize);
- }
+ Plasma::IconWidget* entry = createButton(this);
+ pixmap = getUserIcon(user);
entry->setIcon(pixmap);
- QString username = user.property(KUser::FullName).toString();
- if (username.isEmpty())
- username = session.user;
+ QString username = getUsername(false, user);
entry->setText(username);
connect(entry, SIGNAL(clicked()), m_signalMapper, SLOT(map()));
--
plasma-widget-fastuserswitch packaging
More information about the pkg-kde-commits
mailing list