summaryrefslogtreecommitdiffstats
path: root/src/permission_dialog.cpp
blob: 310bebb40e2a123b857c3e87a9763e7c250d1ede (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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();
}