From: Rodrigo Vivi Date: Thu, 21 Oct 2010 17:27:57 +0000 (-0200) Subject: First commit X-Git-Url: http://git.maemo.org/git/?p=hidecallerid;a=commitdiff_plain First commit Signed-off-by: Rodrigo Vivi --- diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..28f8adb --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +hide-caller-id (0.0.1) unstable; urgency=low + + * Initial Release. + + -- Rodrigo Vivi Wed, 20 Oct 2010 16:11:16 -0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +4 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..9964f4e --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: hide-caller-id +Section: libs +Priority: optional +Maintainer: Rodrigo Vivi +Build-Depends: libqt4-dev (>= 4.6.1), libhildon1-dev, libhildondesktop1-dev +Standards-Version: 3.7.3 + +Package: hide-caller-id +Architecture: any +Section: devel +Depends: libqt4-core (>= 4.6.1), libqt4-gui (>= 4.6.1), qt4-homescreen-loader +Description: Hide Caller Id Homescreen Widget diff --git a/debian/hide-caller-id.install b/debian/hide-caller-id.install new file mode 100644 index 0000000..473ef24 --- /dev/null +++ b/debian/hide-caller-id.install @@ -0,0 +1,3 @@ +/usr/lib/hildon-desktop/hide-caller-id +/usr/share/applications/hildon-home/hide-caller-id.desktop + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..72fe66a --- /dev/null +++ b/debian/rules @@ -0,0 +1,91 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + #docbook-to-man debian/hide-caller-id.sgml > hide-caller-id.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + $(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/hide-caller-id + $(MAKE) INSTALL_ROOT="$(CURDIR)"/debian/hide-caller-id install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + # dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + # dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/hide-caller-id.desktop b/hide-caller-id.desktop new file mode 100644 index 0000000..d48de65 --- /dev/null +++ b/hide-caller-id.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Name=Hide Caller Id +Comment=Hide caller id home desktop item +Type=qt +X-Path=hide-caller-id +X-Multiple-Instances=false +X-home-applet-minwidth=100 +X-home-applet-minheight=72 +Name[en_US]=Hide Caller Id +Exec=/usr/lib/hildon-desktop/hide-caller-id +Icon=hide-caller-id diff --git a/hide-caller-id.pro b/hide-caller-id.pro new file mode 100644 index 0000000..3efb72d --- /dev/null +++ b/hide-caller-id.pro @@ -0,0 +1,25 @@ +TEMPLATE = app + +SOURCES += src/main.cpp \ + src/tpsession.cpp \ + src/idwidget.cpp +HEADERS += \ + src/tpsession.h \ + src/idwidget.h + +include(qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.pri) + +desktop.path = /usr/share/applications/hildon-home +desktop.files = hide-caller-id.desktop + +target.path = /usr/lib/hildon-desktop +INSTALLS += target desktop + +unix { +INCLUDEPATH += /usr/include/telepathy-1.0 +INCLUDEPATH += /usr/include/QtDBus +LIBS += -ltelepathy-qt4 +} + +RESOURCES += \ + icons.qrc diff --git a/hide-caller-id.pro.user b/hide-caller-id.pro.user new file mode 100644 index 0000000..f3ac355 --- /dev/null +++ b/hide-caller-id.pro.user @@ -0,0 +1,189 @@ + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + Default + + + + ProjectExplorer.Project.Target.0 + + Maemo + + Qt4ProjectManager.Target.MaemoDeviceTarget + 0 + 0 + 0 + + + + qmake + + QtProjectManager.QMakeBuildStep + + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/vivijim/pessoal/hide-caller-id-build-maemo + 8 + 9 + true + + + + + qmake + + QtProjectManager.QMakeBuildStep + + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/vivijim/pessoal/hide-caller-id-build-maemo + 8 + 9 + true + + 2 + + + + true + Packaging for Maemo + + Qt4ProjectManager.MaemoPackageCreationStep + + + Deploy to Maemo device + + Qt4ProjectManager.MaemoDeployStep + false + 1 + + /home/vivijim/pessoal/hide-caller-id-build-maemo/hide-caller-id_0.0.1_armel.deb + + + 192.168.2.15 + + + + + + 2010-10-20T16:44:03 + + + 2 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy to Maemo device + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + hide-caller-id + + Qt4ProjectManager.MaemoRunConfiguration + + 1 + + hide-caller-id.pro + + false + + 3768 + true + false + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {751d2bf9-42aa-4f49-99ea-c989cc8805f2} + + + ProjectExplorer.Project.Updater.FileVersion + 8 + + diff --git a/icons.qrc b/icons.qrc new file mode 100644 index 0000000..d509e05 --- /dev/null +++ b/icons.qrc @@ -0,0 +1,6 @@ + + + icons/shown.png + icons/hidden.png + + diff --git a/icons/hidden.png b/icons/hidden.png new file mode 100644 index 0000000..fa2f3d0 Binary files /dev/null and b/icons/hidden.png differ diff --git a/icons/shown.png b/icons/shown.png new file mode 100644 index 0000000..68d6fd1 Binary files /dev/null and b/icons/shown.png differ diff --git a/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.cpp b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.cpp new file mode 100644 index 0000000..ddd962d --- /dev/null +++ b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.cpp @@ -0,0 +1,336 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmaemo5homescreenadaptor.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +static QCoreApplication::EventFilter oldEventFilter; +static QList allDesktopItems; + +static Atom atomByName(const char *name) +{ + Atom atom = XInternAtom(QX11Info::display(), name, False); + if (!atom) + qWarning("Unable to obtain %s atom. This class requires a running Hildon session.", name); + + return atom; +} + +enum HomescreenAtoms +{ + HildonAppletId = 0, + NetWmWindowType = 1, + Utf8String = 2, + HildonTypeHomeApplet = 3, + HildonAppletSettings = 4, + HildonAppletShowSettings = 5, + HildonAppletOnCurrentDesktop = 6, + EnumCount = 7 +}; + +static Atom hsAtoms[EnumCount] = { 0, 0, 0, 0, 0, 0, 0 }; + +static void initAtoms() +{ + hsAtoms[HildonAppletId] = atomByName("_HILDON_APPLET_ID"); + hsAtoms[NetWmWindowType] = atomByName("_NET_WM_WINDOW_TYPE"); + hsAtoms[Utf8String] = atomByName("UTF8_STRING"); + hsAtoms[HildonTypeHomeApplet] = atomByName("_HILDON_WM_WINDOW_TYPE_HOME_APPLET"); + hsAtoms[HildonAppletSettings] = atomByName("_HILDON_APPLET_SETTINGS"); + hsAtoms[HildonAppletShowSettings] = atomByName("_HILDON_APPLET_SHOW_SETTINGS"); + hsAtoms[HildonAppletOnCurrentDesktop] = atomByName("_HILDON_APPLET_ON_CURRENT_DESKTOP"); +} + +/*! \class QMaemo5HomescreenAdaptor + + \brief The QMaemo5HomescreenAdaptor flags a top-level QWidget as homescreen widget + + QMaemo5HomescreenAdaptor is used in conjunction with the Qt for Maemo homescreen + loader. It evaluates the two command line arguments "-plugin-id" and "-write-pipe" + to set up a Qt top-level widget as Maemo 5 homescreen widget. + + Note: By default, the widget will have a black background. In order to make the + widget transparent, set the Qt::WA_TranslucentBackground widget attribute. + + Example: + + \code + QLabel *label = new QLabel("Hello Homescreen"); + new QMaemo5HomescreenAdaptor(label); + label->show(); + \endcode + + Maemo 5 supports homescreen widgets with settings dialogs. To use it, set + the settingsAvailable() property and show a settings dialog when the + settingsRequested() signal is emitted. + + Maemo 5 supports more than one homescreen. In order to determine whether + the homescreen widget is on the currently visible homescreen, connect to + the homescreenChanged() signal. +*/ + +/*! \property QMaemo5HomescreenAdaptor::settingsAvailable + + Set this property to true if the widget can make use of a settings dialog, + otherwise to false. When this property is set to true, the Maemo 5 homescreen + renders a small settings icon on top of the homescreen widget when the + user enters the desktop menu. When the user clicks that settings icon, the + settingsRequested() signal is emitted. + + The default is false. + + \sa settingsRequested() + */ + +/*! \fn void settingsRequested() + + This signal is emitted every time the homescreen widget's settings icon is + invoked by the user. Note that this icon is only visible when the settingsAvailable() + property is set. + + \sa settingsAvailable() + */ + +/*! \fn void homescreenChanged(bool isOnCurrentHomescreen) + + This is signal is emitted when current homescreen changes and the homescreen + widget becomes visible or invisible. The \a isOnCurrentHomescreen argument + indicates whether the homescreen widget is on the current homescreen or not. + + This signal can be used to start/stop background processing in order to save + battery life. + */ + +/*! + Constructs a new QMaemo5HomescreenAdaptor for the given \a widget. + + Note: The widget must be a top-level widget, and must not be reparented + during the lifetime of this adaptor. + + Note: \a widget is also the parent of this class, if the widget is destroyed, + so is this adaptor. + */ +QMaemo5HomescreenAdaptor::QMaemo5HomescreenAdaptor(QWidget *widget) + : QObject(widget), + hasSettings(false) +{ + Q_ASSERT(widget->isWindow()); + + if (!hsAtoms[0]) + initAtoms(); + + Display *display = QX11Info::display(); + + const QStringList args = QApplication::arguments(); + + // parse the command line arguments. + int idx; + if ((idx = args.indexOf(QLatin1String("-plugin-id"))) != -1) { + appletId = args.value(idx + 1); + const QByteArray pluginId = appletId.toUtf8(); + if (!pluginId.isEmpty()) { + XChangeProperty(display, + widget->winId(), + hsAtoms[HildonAppletId], + hsAtoms[Utf8String], 8, PropModeReplace, + reinterpret_cast(pluginId.constData()), + pluginId.length()); + } + } + if ((idx = args.indexOf(QLatin1String("-write-pipe"))) != -1) { + bool ok; + int sockId = args.value(idx + 1).toInt(&ok); + if (ok) { + socketNotifier = new QSocketNotifier(sockId, QSocketNotifier::Exception, this); + connect(socketNotifier, SIGNAL(activated(int)), this, SLOT(socketException())); + } + } + + // set the X11 atoms to flag our widget as homescreen widget + if (!appletId.isEmpty()) { + XChangeProperty(display, + widget->winId(), + hsAtoms[NetWmWindowType], + XA_ATOM, 32, PropModeReplace, + reinterpret_cast(&hsAtoms[HildonTypeHomeApplet]), + 1); + + updateStatus(); + + // --- make this window a child of root + XSetTransientForHint(display, widget->winId(), + RootWindow(display, widget->x11Info().screen())); + + // --- add an x11 event filter + if (!oldEventFilter) + oldEventFilter = QCoreApplication::instance()->setEventFilter(applicationEventFilter); + + allDesktopItems.append(this); + + // --- set WM input hints indicating that we don't want focus events + XWMHints *h = XGetWMHints(display, widget->winId()); + XWMHints wm_hints; + if (!h) { + memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy + h = &wm_hints; + } + h->flags |= InputHint; + h->input = False; + + XSetWMHints(display, widget->winId(), h); + if (h != &wm_hints) + XFree(h); + + widget->setMouseTracking(true); + } +} + +QMaemo5HomescreenAdaptor::~QMaemo5HomescreenAdaptor() +{ + allDesktopItems.removeOne(this); +} + +/*! \internal */ +void QMaemo5HomescreenAdaptor::updateStatus() +{ + if (appletId.isEmpty()) + return; + + Display *display = QX11Info::display(); + + // Set or remove settings property + if (hasSettings) + XChangeProperty(display, + appletWidget()->winId(), + hsAtoms[HildonAppletSettings], + XA_CARDINAL, 32, PropModeReplace, + (const unsigned char *) &(hasSettings), 1); + else + XDeleteProperty(display, + appletWidget()->winId(), + hsAtoms[HildonAppletSettings]); +} + +/*! \internal */ +void QMaemo5HomescreenAdaptor::socketException() +{ + socketNotifier->setEnabled(false); + appletWidget()->close(); +} + +bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event) +{ + return QCoreApplication::sendSpontaneousEvent(receiver, event); +} + + + +/*! \internal */ +bool QMaemo5HomescreenAdaptor::applicationEventFilter(void *message, long *result) +{ + static QPointer lastMouseWidget; + bool retval = false; + + if (oldEventFilter) + retval = oldEventFilter(message, result); + + if (allDesktopItems.isEmpty()) + return retval; + + XEvent *ev = reinterpret_cast(message); + + // Generate a mouse release for a leave Notify (as we don't get the mouse release from X11) + if (ev->type == ButtonPress) { + QPoint globalPos( ev->xbutton.x_root, ev->xbutton.y_root); + QWidget *widget = QWidget::find((WId)ev->xany.window); + if (widget) { + lastMouseWidget = widget->childAt(widget->mapFromGlobal(globalPos)); + if (!lastMouseWidget) + lastMouseWidget = widget; + } + + } else if (ev->type == ButtonRelease) { + lastMouseWidget = 0; + + } else if (ev->type == LeaveNotify) { + if (lastMouseWidget) { + // create a mouse up event that lies in Nirvana. + QPoint pos(-1000, -1000); + QMouseEvent e(QEvent::MouseButtonRelease, pos, pos, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); + qt_sendSpontaneousEvent(lastMouseWidget, &e); + lastMouseWidget = 0; + } + + } else if (ev->type == ClientMessage) { + XClientMessageEvent *cm = (XClientMessageEvent *)message; + if (cm->message_type == hsAtoms[HildonAppletShowSettings]) { + for (int i = 0; i < allDesktopItems.count(); ++i) { + if (allDesktopItems.at(i)->appletWidget()->winId() == ev->xproperty.window) { + emit allDesktopItems.at(i)->settingsRequested(); + retval = true; + } + } + } + } else if (ev->type == PropertyNotify) { + if (ev->xproperty.atom == hsAtoms[HildonAppletOnCurrentDesktop]) { + for (int i = 0; i < allDesktopItems.count(); ++i) { + if (allDesktopItems.at(i)->appletWidget()->winId() == ev->xproperty.window) { + emit allDesktopItems.at(i)->homescreenChanged(ev->xproperty.window == 0); + retval = true; + } + } + } + } + + return retval; +} + diff --git a/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.h b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.h new file mode 100644 index 0000000..9270649 --- /dev/null +++ b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMAEMO5HOMESCREENADAPTOR_H +#define QMAEMO5HOMESCREENADAPTOR_H + +#include +#include +#include + +class QWidget; +class QSocketNotifier; + +class QMaemo5HomescreenAdaptor : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool settingsAvailable READ settingsAvailable WRITE setSettingsAvailable) + +public: + QMaemo5HomescreenAdaptor(QWidget *widget); + ~QMaemo5HomescreenAdaptor(); + + inline void setSettingsAvailable(bool available) + { + hasSettings = available; + updateStatus(); + } + + inline bool settingsAvailable() const + { + return hasSettings; + } + +Q_SIGNALS: + void settingsRequested(); + void homescreenChanged(bool isOnCurrentHomescreen); + +private Q_SLOTS: + void socketException(); + +private: + inline QWidget *appletWidget() const { return static_cast(parent()); } + + void updateStatus(); + + static bool applicationEventFilter(void *message, long *result); + + bool hasSettings; + QString appletId; + QSocketNotifier *socketNotifier; +}; + +#endif diff --git a/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.pri b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.pri new file mode 100644 index 0000000..73d41c3 --- /dev/null +++ b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.pri @@ -0,0 +1,4 @@ +HEADERS += $$PWD/qmaemo5homescreenadaptor.h +SOURCES += $$PWD/qmaemo5homescreenadaptor.cpp + +INCLUDEPATH += $$PWD diff --git a/src/idwidget.cpp b/src/idwidget.cpp new file mode 100644 index 0000000..08fac3f --- /dev/null +++ b/src/idwidget.cpp @@ -0,0 +1,42 @@ +#include "idwidget.h" + +IdWidget::IdWidget(tpSession *tp) + : QPushButton() +{ + this->tp = tp; + setAttribute(Qt::WA_TranslucentBackground); + QObject::connect(this, SIGNAL(clicked()), this, SLOT(changeState())); + QObject::connect(tp, SIGNAL(privacyUpdated(bool)), this, SLOT(setButtonState(bool))); + pHidden = new QPixmap(":/icons/hidden.png"); + pShown = new QPixmap(":/icons/shown.png"); +} + +void IdWidget::setButtonState(bool showId) +{ + QPixmap *pixmap; + this->showId = showId; + + if(showId) { + pixmap = pShown; + setText("Id Shown"); + } + else { + pixmap = pHidden; + setText("Id Hidden"); + } + + QIcon icon(*pixmap); + QSize iconSize(pixmap->width(), pixmap->height()); + setIconSize(iconSize); + setIcon(icon); +} + +void IdWidget::changeState() +{ + if(showId) { + tp->setPrivacy(false); + } + else { + tp->setPrivacy(true); + } +} diff --git a/src/idwidget.h b/src/idwidget.h new file mode 100644 index 0000000..7e8840d --- /dev/null +++ b/src/idwidget.h @@ -0,0 +1,45 @@ +#ifndef IDWIDGET_H +#define IDWIDGET_H + +#include +#include +#include +#include "tpsession.h" + +class IdWidget : public QPushButton +{ + Q_OBJECT + +private: + + bool showId; + tpSession *tp; + QPixmap *pHidden; + QPixmap *pShown; + +public: + IdWidget(tpSession *tp); + + QSize sizeHint() const + { + return QSize(200, 75); + } + +public slots: + void changeState(); + void setButtonState(bool showId); + +protected: + void paintEvent(QPaintEvent *event) + { + QPainter p(this); + p.setBrush(QColor(0, 0, 0, 128)); + p.setPen(Qt::NoPen); + p.drawRoundedRect(rect(), 25, 25); + p.end(); + + QPushButton::paintEvent(event); + } +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..fe54766 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file was based on one of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmaemo5homescreenadaptor.h" +#include "idwidget.h" +#include "tpsession.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + IdWidget *idWidget = new IdWidget(new tpSession()); + QMaemo5HomescreenAdaptor *adaptor = new QMaemo5HomescreenAdaptor(idWidget); + adaptor->setSettingsAvailable(false); + idWidget->show(); + + app.exec(); +} diff --git a/src/testwidget.h b/src/testwidget.h new file mode 100644 index 0000000..0fadaff --- /dev/null +++ b/src/testwidget.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IDWIDGET_H +#define IDWIDGET_H + +#include +#include +#include +#include "tpsession.h" + +class IdWidget : public QPushButton +{ + Q_OBJECT + +public: + + bool showId; + tpSession* tp; + + IdWidget() + : QPushButton() + { + setAttribute(Qt::WA_TranslucentBackground); + QPixmap* pixmap = new QPixmap("/usr/share/vivi/shown.png"); + showId = TRUE; + setText("Id Shown"); + QIcon icon(*pixmap); + QSize iconSize(pixmap->width(), pixmap->height()); + setIconSize(iconSize); + setIcon(icon); + QObject::connect(this, SIGNAL(clicked()), this, SLOT(changeState())); + } + + IdWidget(tpSession tp) + { + this->tp = tp; + } + + QSize sizeHint() const + { + return 1.2 * QPushButton::sizeHint(); + } + +public slots: + + void changeState() + { + QPixmap* pixmap; + if(showId) { + pixmap = new QPixmap("/usr/share/vivi/hidden.png"); + showId = FALSE; + setText("Id Hidden"); + tp->setPrivacy(true); + } + else { + pixmap = new QPixmap("/usr/share/vivi/shown.png"); + showId = TRUE; + setText("Id Shown"); + tp->setPrivacy(false); + } + QIcon icon(*pixmap); + QSize iconSize(pixmap->width(), pixmap->height()); + setIconSize(iconSize); + setIcon(icon); + } + +protected: + void paintEvent(QPaintEvent *event) + { + QPainter p(this); + p.setBrush(QColor(0, 0, 0, 128)); + p.setPen(Qt::NoPen); + p.drawRoundedRect(rect(), 25, 25); + p.end(); + + QPushButton::paintEvent(event); + } +}; + +#endif diff --git a/src/tpsession.cpp b/src/tpsession.cpp new file mode 100644 index 0000000..5ad4311 --- /dev/null +++ b/src/tpsession.cpp @@ -0,0 +1,147 @@ +#include "tpsession.h" + +#include +#include +#include +#include +#include +#include +#include + +tpSession::tpSession() +{ + QDBusConnection bus = QDBusConnection::sessionBus(); + mAM = AccountManager::create(bus, + AccountFactory::create(bus, Account::FeatureCore), + ConnectionFactory::create(bus, Connection::FeatureCore), + ChannelFactory::create(bus)); + + connect(mAM->becomeReady(), + SIGNAL(finished(Tp::PendingOperation *)), + SLOT(onAMReady(Tp::PendingOperation *))); +} + +void tpSession::onAMReady(Tp::PendingOperation *op) +{ + if (op->isError()) { + qWarning() << "error making AM ready"; + return; + } + + mAccount = mAM->accountForPath("/org/freedesktop/Telepathy/Account/ring/tel/ring"); + if (!mAccount) { + qWarning() << "no account for ring found"; + return; + } + + //connect(mAccount->baseInterface(), SIGNAL(AccountPropertyChanged(const QVariantMap&)), this, SLOT(onPrivacyChanged(const QVariantMap&))); + if (!mAccount->haveConnection()) { + connect(mAccount.data(), + SIGNAL(haveConnectionChanged(bool)), + SLOT(onAccountHaveConnectionChanged(bool))); + } else { + mConnection = mAccount->connection(); + retrievePrivacy(); + } +} + +void tpSession::onPropertyChanged(const QVariantMap& properties) +{ + qDebug() << "TODO: change state when Privacy has been updated by someone else" << properties; +} + +void tpSession::onAccountHaveConnectionChanged(bool haveConnection) +{ + if (haveConnection) { + mConnection = mAccount->connection(); + retrievePrivacy(); + } +} + +void tpSession::onSetPrivacyFinished(Tp::PendingOperation *op) +{ + if (op->isError()) { + qWarning() << "unable to set com.nokia.Telepathy.Connection.Interface.GSM.Privacy"; + return; + } + + qDebug() << "com.nokia.Telepathy.Connection.Interface.GSM.Privacy property set"; + emit privacyUpdated(showId); +} + +void tpSession::onGotPrivacy(QDBusPendingCallWatcher *watcher) +{ + QDBusPendingReply reply = *watcher; + + if (reply.isError()) { + qWarning() << "unable to get com.nokia.Telepathy.Connection.Interface.GSM.Privacy"; + return; + } + + // Don't ask me why, but no-id == showId and id == hide it. + if(qdbus_cast(reply.value()) == QVariant("no-id")) + showId = true; + else + showId = false; + emit privacyUpdated(showId); + + qDebug() << "com.nokia.Telepathy.Connection.Interface.GSM.Privacy property set"; +} + +void tpSession::retrievePrivacy() +{ + if (!mConnection) { + qWarning() << "Account Manager connection unavailable"; + return; + } + + if (!mConnection->hasInterface("com.nokia.Telepathy.Connection.Interface.GSM")) { + qWarning() << "connection does not have interface GSM"; + return; + } + + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( + mConnection->propertiesInterface()->Get( + QLatin1String("com.nokia.Telepathy.Connection.Interface.GSM"), + QLatin1String("Privacy")), this); + + connect(watcher, + SIGNAL(finished(QDBusPendingCallWatcher *)), + SLOT(onGotPrivacy(QDBusPendingCallWatcher *))); + + qDebug() << "com.nokia.Telepathy.Connection.Interface.GSM.Privacy retrieved"; +} + +void tpSession::setPrivacy(bool value) +{ + showId = value; + + if (!mConnection) { + qWarning() << "Account Manager connection unavailable"; + return; + } + + if (!mConnection->hasInterface("com.nokia.Telepathy.Connection.Interface.GSM")) { + qWarning() << "connection does not have interface GSM"; + return; + } + + PendingVoid *call; + // Don't ask me why, but no-id == showId and id == hide it. + if(value) + call = new PendingVoid( + mConnection->propertiesInterface()->Set( + QLatin1String("com.nokia.Telepathy.Connection.Interface.GSM"), + QLatin1String("Privacy"), QDBusVariant("no-id")), + this); + else + call = new PendingVoid( + mConnection->propertiesInterface()->Set( + QLatin1String("com.nokia.Telepathy.Connection.Interface.GSM"), + QLatin1String("Privacy"), QDBusVariant("id")), + this); + + connect(call, + SIGNAL(finished(Tp::PendingOperation*)), + SLOT(onSetPrivacyFinished(Tp::PendingOperation*))); +} diff --git a/src/tpsession.h b/src/tpsession.h new file mode 100644 index 0000000..9281e13 --- /dev/null +++ b/src/tpsession.h @@ -0,0 +1,36 @@ +#ifndef TPSESSION_H +#define TPSESSION_H + +#include +#include + +using namespace Tp; + +class tpSession : public QObject +{ + Q_OBJECT + +public: + tpSession(); + ~tpSession() {} + void setPrivacy(bool showId); + void retrievePrivacy(); + +private Q_SLOTS: + void onAMReady(Tp::PendingOperation *op); + void onAccountHaveConnectionChanged(bool value); + void onSetPrivacyFinished(Tp::PendingOperation *op); + void onGotPrivacy(QDBusPendingCallWatcher *op); + void onPropertyChanged(const QVariantMap& properties); + +private: + AccountManagerPtr mAM; + AccountPtr mAccount; + ConnectionPtr mConnection; + bool showId; + +signals: + void privacyUpdated(bool showId); +}; + +#endif // TPSESSION_H diff --git a/welcome b/welcome deleted file mode 100644 index e69de29..0000000