Changeset View
Changeset View
Standalone View
Standalone View
src/option/k3bdevicewidget.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 51 | : QWidget( parent ), | |||
---|---|---|---|---|---|
52 | m_deviceManager( manager ), | 52 | m_deviceManager( manager ), | ||
53 | m_writerParentViewItem( 0 ), | 53 | m_writerParentViewItem( 0 ), | ||
54 | m_readerParentViewItem( 0 ) | 54 | m_readerParentViewItem( 0 ) | ||
55 | { | 55 | { | ||
56 | // message widget | 56 | // message widget | ||
57 | m_messageWidget = new KMessageWidget( this ); | 57 | m_messageWidget = new KMessageWidget( this ); | ||
58 | m_messageWidget->hide(); | 58 | m_messageWidget->hide(); | ||
59 | m_messageWidget->setWordWrap( true ); | 59 | m_messageWidget->setWordWrap( true ); | ||
60 | #ifdef ENABLE_PERMISSION_HELPER | | |||
61 | m_addToGroupAction = new QAction( QIcon::fromTheme("dialog-password"), QString(), this ); | 60 | m_addToGroupAction = new QAction( QIcon::fromTheme("dialog-password"), QString(), this ); | ||
62 | #endif | | |||
63 | 61 | | |||
64 | // buttons | 62 | // buttons | ||
65 | // ------------------------------------------------ | 63 | // ------------------------------------------------ | ||
66 | QPushButton* buttonRefreshDevices = new QPushButton( QIcon::fromTheme( "view-refresh" ), i18n( "Refresh" ), this ); | 64 | QPushButton* buttonRefreshDevices = new QPushButton( QIcon::fromTheme( "view-refresh" ), i18n( "Refresh" ), this ); | ||
67 | buttonRefreshDevices->setToolTip( i18n( "Rescan the devices" ) ); | 65 | buttonRefreshDevices->setToolTip( i18n( "Rescan the devices" ) ); | ||
68 | QHBoxLayout* refreshButtonGrid = new QHBoxLayout; | 66 | QHBoxLayout* refreshButtonGrid = new QHBoxLayout; | ||
69 | refreshButtonGrid->setContentsMargins( 0, 0, 0, 0 ); | 67 | refreshButtonGrid->setContentsMargins( 0, 0, 0, 0 ); | ||
70 | refreshButtonGrid->addStretch(); | 68 | refreshButtonGrid->addStretch(); | ||
Show All 20 Lines | |||||
91 | frameLayout->addWidget( m_viewDevices, 1 ); | 89 | frameLayout->addWidget( m_viewDevices, 1 ); | ||
92 | frameLayout->addLayout( refreshButtonGrid, 0 ); | 90 | frameLayout->addLayout( refreshButtonGrid, 0 ); | ||
93 | // ------------------------------------------------ | 91 | // ------------------------------------------------ | ||
94 | 92 | | |||
95 | // connections | 93 | // connections | ||
96 | // ------------------------------------------------ | 94 | // ------------------------------------------------ | ||
97 | connect( buttonRefreshDevices, SIGNAL(clicked()), SIGNAL(refreshButtonClicked()) ); | 95 | connect( buttonRefreshDevices, SIGNAL(clicked()), SIGNAL(refreshButtonClicked()) ); | ||
98 | connect( m_deviceManager, SIGNAL(changed()), SLOT(init()) ); | 96 | connect( m_deviceManager, SIGNAL(changed()), SLOT(init()) ); | ||
99 | #ifdef ENABLE_PERMISSION_HELPER | | |||
100 | connect( m_addToGroupAction, SIGNAL(triggered(bool)), SLOT(addUserToGroup()) ); | 97 | connect( m_addToGroupAction, SIGNAL(triggered(bool)), SLOT(addUserToGroup()) ); | ||
101 | #endif | | |||
102 | // ------------------------------------------------ | 98 | // ------------------------------------------------ | ||
103 | } | 99 | } | ||
104 | 100 | | |||
105 | 101 | | |||
106 | K3b::DeviceWidget::~DeviceWidget() | 102 | K3b::DeviceWidget::~DeviceWidget() | ||
107 | { | 103 | { | ||
108 | } | 104 | } | ||
109 | 105 | | |||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 233 | if( m_deviceGroup != "root" ) { | |||
242 | Q_FOREACH( gid_t gid, gids ) { | 238 | Q_FOREACH( gid_t gid, gids ) { | ||
243 | if( ::group* g = ::getgrgid( gid ) ) { | 239 | if( ::group* g = ::getgrgid( gid ) ) { | ||
244 | groupNames.insert( QString::fromLocal8Bit( g->gr_name ) ); | 240 | groupNames.insert( QString::fromLocal8Bit( g->gr_name ) ); | ||
245 | } | 241 | } | ||
246 | } | 242 | } | ||
247 | 243 | | |||
248 | if (!groupNames.contains(m_deviceGroup)) { | 244 | if (!groupNames.contains(m_deviceGroup)) { | ||
249 | QString messageText = i18n("In order to give K3b full access to the writer device the current user needs be added to a group <em>%1</em>.", m_deviceGroup); | 245 | QString messageText = i18n("In order to give K3b full access to the writer device the current user needs be added to a group <em>%1</em>.", m_deviceGroup); | ||
250 | #ifndef ENABLE_PERMISSION_HELPER | | |||
251 | messageText += i18n("<br/>The Permission helper that could do this for you was not enabled during build.<br/>" | | |||
252 | "Please rebuild the package with the Permission helper enabled or contact your distribution."); | | |||
253 | #endif | | |||
254 | m_messageWidget->setMessageType(KMessageWidget::Warning); | 246 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||
255 | m_messageWidget->setText(messageText); | 247 | m_messageWidget->setText(messageText); | ||
256 | #ifdef ENABLE_PERMISSION_HELPER | | |||
257 | m_messageWidget->addAction(m_addToGroupAction); | 248 | m_messageWidget->addAction(m_addToGroupAction); | ||
258 | m_addToGroupAction->setText(i18n("Add")); | 249 | m_addToGroupAction->setText(i18n("Add")); | ||
259 | #endif | | |||
260 | m_messageWidget->animatedShow(); | 250 | m_messageWidget->animatedShow(); | ||
261 | } | 251 | } | ||
262 | } | 252 | } | ||
263 | } | 253 | } | ||
264 | } | 254 | } | ||
265 | 255 | | |||
266 | void K3b::DeviceWidget::addUserToGroup() | 256 | void K3b::DeviceWidget::addUserToGroup() | ||
267 | { | 257 | { | ||
268 | #ifdef ENABLE_PERMISSION_HELPER | | |||
269 | QVariantMap args; | 258 | QVariantMap args; | ||
270 | args["groupName"] = m_deviceGroup; | 259 | args["groupName"] = m_deviceGroup; | ||
271 | args["userName"] = QString::fromLocal8Bit(getpwuid(getuid())->pw_name); | 260 | args["userName"] = QString::fromLocal8Bit(getpwuid(getuid())->pw_name); | ||
272 | 261 | | |||
273 | KAuth::Action action("org.kde.k3b.addtogroup"); | 262 | KAuth::Action action("org.kde.k3b.addtogroup"); | ||
274 | action.setHelperId("org.kde.k3b"); | 263 | action.setHelperId("org.kde.k3b"); | ||
275 | action.setParentWidget(this); | 264 | action.setParentWidget(this); | ||
276 | action.setArguments(args); | 265 | action.setArguments(args); | ||
277 | 266 | | |||
278 | KAuth::ExecuteJob* job = action.execute(); | 267 | KAuth::ExecuteJob* job = action.execute(); | ||
279 | connect( job, &KAuth::ExecuteJob::result, [this, job]() | 268 | connect( job, &KAuth::ExecuteJob::result, [this, job]() | ||
280 | { | 269 | { | ||
281 | if( job->error() == KJob::NoError ) { | 270 | if( job->error() == KJob::NoError ) { | ||
282 | m_messageWidget->removeAction(m_addToGroupAction); | 271 | m_messageWidget->removeAction(m_addToGroupAction); | ||
283 | m_messageWidget->setMessageType(KMessageWidget::Information); | 272 | m_messageWidget->setMessageType(KMessageWidget::Information); | ||
284 | m_messageWidget->setText(i18n("Please relogin to apply the changes.")); | 273 | m_messageWidget->setText(i18n("Please relogin to apply the changes.")); | ||
285 | } else { | 274 | } else { | ||
286 | m_messageWidget->setMessageType(KMessageWidget::Error); | 275 | m_messageWidget->setMessageType(KMessageWidget::Error); | ||
287 | m_messageWidget->setText(i18n("Unable to execute the action: %1 (Error code: %2)", job->errorString(), job->error())); | 276 | m_messageWidget->setText(i18n("Unable to execute the action: %1 (Error code: %2)", job->errorString(), job->error())); | ||
288 | m_addToGroupAction->setText(i18n("Retry")); | 277 | m_addToGroupAction->setText(i18n("Retry")); | ||
289 | } | 278 | } | ||
290 | } ); | 279 | } ); | ||
291 | job->start(); | 280 | job->start(); | ||
292 | #endif | | |||
293 | } | 281 | } |