Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>pull/6/head
parent
87769ed51d
commit
a5eb53fcbc
@ -0,0 +1,209 @@
|
||||
/*******************************************************************************
|
||||
XDG desktop portal implementation for TDE
|
||||
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
|
||||
|
||||
Avatar detection code is based on code from the Redmond KSplash theme
|
||||
Copyright © 2001-2003 Brian Ledbetter 2001-2003 <brian@shadowcom.net>
|
||||
Copyright © 2003 Ravikiran Rajagopal 2003 <ravi@kde.org>
|
||||
|
||||
This program or library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Improvements and feedback are welcome!
|
||||
*******************************************************************************/
|
||||
|
||||
// TQt
|
||||
#include <tqfile.h>
|
||||
#include <tqhbox.h>
|
||||
#include <tqlabel.h>
|
||||
#include <tqdbusdata.h>
|
||||
|
||||
// TDE
|
||||
#include <kstandarddirs.h>
|
||||
#include <ksimpleconfig.h>
|
||||
#include <tdelocale.h>
|
||||
#include <twin.h>
|
||||
#include <kuser.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
// Portal
|
||||
#include "permission_dialog.h"
|
||||
#include "account_portal.h"
|
||||
#include "account_portal.moc"
|
||||
|
||||
#define TQSTRING_TO_DBUS_VARIANT(x) \
|
||||
TQT_DBusData::fromString(x).getAsVariantData().toVariant()
|
||||
|
||||
TDEAccountPortal::TDEAccountPortal(TQT_DBusConnection &connection)
|
||||
: m_connection(connection)
|
||||
{
|
||||
}
|
||||
|
||||
TDEAccountPortal::~TDEAccountPortal()
|
||||
{
|
||||
}
|
||||
|
||||
void TDEAccountPortal::handleMethodReply(const TQT_DBusMessage &reply)
|
||||
{
|
||||
m_connection.send(reply);
|
||||
}
|
||||
|
||||
bool TDEAccountPortal::handleSignalSend(const TQT_DBusMessage& reply) {
|
||||
handleMethodReply(reply);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TDEAccountPortal::GetUserInformation(const TQT_DBusObjectPath& handle,
|
||||
const TQString& app_id,
|
||||
const TQString& window,
|
||||
const TQT_DBusVariantMap& options,
|
||||
TQ_UINT32& response,
|
||||
TQT_DBusVariantMap& results,
|
||||
TQT_DBusError& error)
|
||||
{
|
||||
Dictionary details;
|
||||
|
||||
if (OPTION_VALID("reason", "s"))
|
||||
{
|
||||
TQString reason(options["reason"].value.toString());
|
||||
if (!reason.isEmpty())
|
||||
{
|
||||
details[i18n("Reason")] = reason;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to detect which application requested the permission
|
||||
WId wid = parse_window_id(window);
|
||||
ApplicationInfo app = application_info_from_wid(wid);
|
||||
|
||||
if (!app.path.isEmpty())
|
||||
details[i18n("Path")] = app.path;
|
||||
|
||||
// Run the dialog
|
||||
TDEPermissionDialog *dialog = new TDEPermissionDialog(
|
||||
app.name,
|
||||
i18n("Account information"),
|
||||
"user-info",
|
||||
details
|
||||
);
|
||||
AccountInfo info = getAccountInfo();
|
||||
appendDataPreview(dialog, info);
|
||||
|
||||
if (wid > 0) KWin::setMainWindow(dialog, wid);
|
||||
|
||||
if (dialog->exec() == KDialogBase::Yes)
|
||||
{
|
||||
response = 0;
|
||||
results.insert("id", TQSTRING_TO_DBUS_VARIANT(info.userId));
|
||||
results.insert("name", TQSTRING_TO_DBUS_VARIANT(info.realName));
|
||||
results.insert("image", TQSTRING_TO_DBUS_VARIANT(info.avatarPath));
|
||||
}
|
||||
else response = 1;
|
||||
|
||||
delete dialog;
|
||||
return true;
|
||||
}
|
||||
|
||||
AccountInfo TDEAccountPortal::getAccountInfo()
|
||||
{
|
||||
AccountInfo info;
|
||||
KUser user;
|
||||
info.userId = TQString::number(user.uid());
|
||||
info.loginName = user.loginName();
|
||||
info.realName = user.fullName();
|
||||
info.homeDirectory = user.homeDir();
|
||||
findUserAvatar(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
void TDEAccountPortal::findUserAvatar(AccountInfo &info)
|
||||
{
|
||||
// Parse tdmrc settings to determine face source and system location
|
||||
const int fAdminOnly = 1;
|
||||
const int fAdminFirst = fAdminOnly + 1;
|
||||
const int fUserFirst = fAdminFirst + 1;
|
||||
const int fUserOnly = fUserFirst + 1;
|
||||
|
||||
int faceSource = fAdminOnly;
|
||||
TDEConfig *tdmconfig = new TDEConfig("tdm/tdmrc", true);
|
||||
tdmconfig->setGroup("X-*-Greeter");
|
||||
|
||||
TQString fs = tdmconfig->readEntry("FaceSource");
|
||||
if (fs == TQString::fromLatin1("UserOnly"))
|
||||
faceSource = fUserOnly;
|
||||
else if (fs == TQString::fromLatin1("PreferUser"))
|
||||
faceSource = fUserFirst;
|
||||
else if (fs == TQString::fromLatin1("PreferAdmin"))
|
||||
faceSource = fAdminFirst;
|
||||
else
|
||||
faceSource = fAdminOnly;
|
||||
|
||||
TQString userPicsDir = tdmconfig->readEntry("FaceDir",
|
||||
TDEGlobal::dirs()->resourceDirs("data").last() + "tdm/faces") + '/';
|
||||
|
||||
delete tdmconfig;
|
||||
|
||||
// Faces provided by administrator (default and per user)
|
||||
const TQString systemDefault(userPicsDir + ".default.face.icon");
|
||||
const TQString systemUser(userPicsDir + info.loginName + ".face.icon");
|
||||
|
||||
TQString avatar;
|
||||
if (faceSource == fAdminFirst)
|
||||
{
|
||||
avatar = systemUser;
|
||||
if (!TQFile::exists(avatar))
|
||||
faceSource = fUserOnly;
|
||||
}
|
||||
|
||||
if (faceSource >= fUserFirst)
|
||||
{
|
||||
avatar = info.homeDirectory + "/.face.icon";
|
||||
if (!TQFile::exists(avatar) && faceSource == fUserFirst)
|
||||
avatar = systemUser;
|
||||
|
||||
if (!TQFile::exists(avatar))
|
||||
avatar = systemDefault;
|
||||
}
|
||||
|
||||
if (faceSource <= fAdminOnly)
|
||||
{
|
||||
avatar = systemUser;
|
||||
if (!TQFile::exists(avatar))
|
||||
avatar = systemDefault;
|
||||
}
|
||||
|
||||
info.avatarPath = avatar;
|
||||
}
|
||||
|
||||
void TDEAccountPortal::appendDataPreview(TDEPermissionDialog *dlg, AccountInfo info)
|
||||
{
|
||||
TQHBox *frame = new TQHBox(dlg);
|
||||
frame->setFrameStyle(TQFrame::StyledPanel | TQFrame::Sunken);
|
||||
|
||||
TQLabel *avatar = new TQLabel(frame);
|
||||
avatar->setPixmap(TQPixmap(info.avatarPath));
|
||||
|
||||
TQString userDataStr = "<qt><h1>%1</h1><hr>ID: %2</qt>";
|
||||
userDataStr = userDataStr.arg(info.realName, info.userId);
|
||||
TQLabel *userData = new TQLabel(userDataStr, frame);
|
||||
|
||||
avatar->setMargin(TDEPermissionDialog::spacingHint());
|
||||
userData->setMargin(TDEPermissionDialog::spacingHint());
|
||||
|
||||
frame->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Fixed);
|
||||
|
||||
dlg->appendWidget(frame);
|
||||
}
|
||||
|
||||
// kate: replace-tabs true; tab-width 4; indent-width 4;
|
@ -0,0 +1,73 @@
|
||||
/*******************************************************************************
|
||||
XDG desktop portal implementation for TDE
|
||||
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
|
||||
|
||||
This program or library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Improvements and feedback are welcome!
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ACCOUNT_PORTAL_H
|
||||
#define __ACCOUNT_PORTAL_H
|
||||
|
||||
// Portal
|
||||
#include "interfaces/accountInterface.h"
|
||||
#include "interface.h"
|
||||
|
||||
struct AccountInfo
|
||||
{
|
||||
TQString userId;
|
||||
TQString loginName;
|
||||
TQString realName;
|
||||
TQString homeDirectory;
|
||||
TQString avatarPath;
|
||||
};
|
||||
|
||||
class TDEPermissionDialog;
|
||||
|
||||
class TDEAccountPortal : public TQObject,
|
||||
public org::freedesktop::impl::portal::AccountInterface
|
||||
{
|
||||
public:
|
||||
INTERFACE("org.freedesktop.impl.portal.Account")
|
||||
|
||||
TDEAccountPortal(TQT_DBusConnection &connection);
|
||||
virtual ~TDEAccountPortal();
|
||||
|
||||
protected:
|
||||
virtual void handleMethodReply(const TQT_DBusMessage& reply);
|
||||
virtual bool handleSignalSend(const TQT_DBusMessage& reply);
|
||||
|
||||
virtual bool GetUserInformation(const TQT_DBusObjectPath& handle,
|
||||
const TQString& app_id,
|
||||
const TQString& window,
|
||||
const TQT_DBusVariantMap& options,
|
||||
TQ_UINT32& response,
|
||||
TQT_DBusVariantMap& results,
|
||||
TQT_DBusError& error);
|
||||
|
||||
AccountInfo getAccountInfo();
|
||||
void appendDataPreview(TDEPermissionDialog *dlg, AccountInfo info);
|
||||
|
||||
private:
|
||||
void findUserAvatar(AccountInfo &info);
|
||||
|
||||
private:
|
||||
TQT_DBusConnection m_connection;
|
||||
};
|
||||
|
||||
#endif // __ACCOUNT_PORTAL_H
|
||||
|
||||
// kate: replace-tabs true; tab-width 4; indent-width 4;
|
@ -0,0 +1,100 @@
|
||||
/*******************************************************************************
|
||||
XDG desktop portal implementation for TDE
|
||||
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
|
||||
|
||||
This program or library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Improvements and feedback are welcome!
|
||||
*******************************************************************************/
|
||||
|
||||
// TQt
|
||||
#include <tqvbox.h>
|
||||
#include <tqhbox.h>
|
||||
#include <tqlayout.h>
|
||||
#include <tqlabel.h>
|
||||
|
||||
// TDE
|
||||
#include <tdelocale.h>
|
||||
#include <kiconloader.h>
|
||||
#include <twin.h>
|
||||
|
||||
// Portal
|
||||
#include "permission_dialog.h"
|
||||
#include "permission_dialog.moc"
|
||||
|
||||
TDEPermissionDialog::TDEPermissionDialog(TQString application, TQString feature,
|
||||
TQString icon, Dictionary details)
|
||||
|
||||
: KDialogBase(TQString::null, /* we set plain caption below */
|
||||
KDialogBase::Yes | KDialogBase::No | KDialogBase::Details,
|
||||
KDialogBase::NoDefault, KDialogBase::No,
|
||||
nullptr, "permissiondlg", true, true,
|
||||
KGuiItem(i18n("&Allow"), "button_ok"),
|
||||
KGuiItem(i18n("&Deny"), "button_cancel")),
|
||||
|
||||
m_vbox(new TQVBox(this)),
|
||||
m_hbox(new TQHBox(m_vbox)),
|
||||
m_icon(new TQLabel(m_hbox)),
|
||||
m_text(new TQLabel(m_hbox)),
|
||||
m_detail(new TQLabel(this))
|
||||
|
||||
{
|
||||
setPlainCaption(i18n("Permission request"));
|
||||
|
||||
TQString text;
|
||||
if (!application.isEmpty())
|
||||
{
|
||||
text = "<qt>Application \"%1\" has requested the following permission: <b>%2</b></qt>";
|
||||
text = text.arg(application);
|
||||
}
|
||||
else
|
||||
text = "<qt>An unknown application has requested the following permission: <b>%1</b></qt>";
|
||||
m_text->setText(text.arg(feature));
|
||||
|
||||
m_icon->setPixmap(DesktopIcon(icon));
|
||||
|
||||
m_icon->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed);
|
||||
m_text->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Fixed);
|
||||
|
||||
TQString detailStr = "<qt><table><tbody>";
|
||||
for (Dictionary::iterator it = details.begin(); it != details.end(); ++it)
|
||||
{
|
||||
detailStr += TQString("<tr><td>%1:</td><td><b>%2</b></td></tr>")
|
||||
.arg(it.key(), it.data());
|
||||
}
|
||||
detailStr += "</tbody></table></qt>";
|
||||
m_detail->setText(detailStr);
|
||||
|
||||
setMainWidget(m_vbox);
|
||||
setDetailsWidget(m_detail);
|
||||
|
||||
m_hbox->setSizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Fixed);
|
||||
|
||||
// m_vbox->setMargin(KDialogBase::marginHint());
|
||||
m_icon->setMargin(KDialogBase::spacingHint());
|
||||
m_text->setMargin(KDialogBase::spacingHint());
|
||||
raise();
|
||||
}
|
||||
|
||||
TDEPermissionDialog::~TDEPermissionDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void TDEPermissionDialog::appendWidget(TQWidget *widget)
|
||||
{
|
||||
m_vbox->hide();
|
||||
widget->reparent(m_vbox, TQPoint());
|
||||
m_vbox->show();
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*******************************************************************************
|
||||
XDG desktop portal implementation for TDE
|
||||
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
|
||||
|
||||
This program or library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Improvements and feedback are welcome!
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __PERMISSION_DIALOG_H
|
||||
#define __PERMISSION_DIALOG_H
|
||||
|
||||
// TDE
|
||||
#include <kdialogbase.h>
|
||||
|
||||
typedef TQMap<TQString, TQString> Dictionary;
|
||||
|
||||
class TQVBox;
|
||||
class TQHBox;
|
||||
class TQLabel;
|
||||
|
||||
class TDEPermissionDialog : public KDialogBase
|
||||
{
|
||||
TQ_OBJECT
|
||||
|
||||
public:
|
||||
TDEPermissionDialog(TQString application, TQString feature,
|
||||
TQString icon = "messagebox_question",
|
||||
Dictionary details = {});
|
||||
virtual ~TDEPermissionDialog();
|
||||
|
||||
void appendWidget(TQWidget *widget);
|
||||
|
||||
private:
|
||||
TQVBox *m_vbox;
|
||||
TQHBox *m_hbox;
|
||||
TQLabel *m_icon;
|
||||
TQLabel *m_text;
|
||||
TQLabel *m_detail;
|
||||
};
|
||||
|
||||
#endif // __PERMISSION_DIALOG_H
|
Loading…
Reference in new issue