Commit 3c73a555 authored by Sergio Martins's avatar Sergio Martins
Browse files

Move the code that starts korganizer and opens the editor to a function.

Will be easier to get rid of it, or ifdef it mobile only.
parent 2c6b676d
......@@ -419,56 +419,7 @@ void AlarmDialog::edit()
return;
}
if ( !QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.korganizer" ) ) {
if ( KToolInvocation::startServiceByDesktopName( "korganizer", QString() ) ) {
KMessageBox::error(
this,
i18nc( "@info",
"Could not start KOrganizer so editing is not possible." ) );
return;
}
}
org::kde::korganizer::Korganizer korganizer(
"org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() );
kDebug() << "editing incidence " << incidence->summary();
if ( !korganizer.editIncidence( incidence->uid() ) ) {
KMessageBox::error(
this,
i18nc( "@info",
"An internal KOrganizer error occurred attempting to modify \"%1\"",
cleanSummary( incidence->summary() ) ) );
}
// get desktop # where korganizer (or kontact) runs
QString object =
QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.kontact" ) ?
"kontact/MainWindow_1" : "korganizer/MainWindow_1";
QDBusInterface korganizerObj( "org.kde.korganizer", '/' + object );
#ifdef Q_WS_X11
QDBusReply<int> reply = korganizerObj.call( "winId" );
if ( reply.isValid() ) {
int window = reply;
int desktop = KWindowSystem::windowInfo( window, NET::WMDesktop ).desktop();
if ( KWindowSystem::currentDesktop() == desktop ) {
KWindowSystem::minimizeWindow( winId(), false );
} else {
KWindowSystem::setCurrentDesktop( desktop );
}
KWindowSystem::activateWindow( KWindowSystem::transientFor( window ) );
}
#elif defined(Q_WS_WIN)
// WId is a typedef to a void* on windows
QDBusReply<qlonglong> reply = korganizerObj.call( "winId" );
if ( reply.isValid() ) {
qlonglong window = reply;
KWindowSystem::minimizeWindow( winId(), false );
KWindowSystem::allowExternalProcessWindowActivation();
KWindowSystem::activateWindow( reinterpret_cast<WId>(window) );
}
#else
// TODO (mac)
#endif
openEditorThroughKOrganizer( incidence );
}
void AlarmDialog::suspend()
......@@ -897,4 +848,59 @@ void AlarmDialog::keyPressEvent( QKeyEvent *e )
KDialog::keyPressEvent( e );
}
bool AlarmDialog::openEditorThroughKOrganizer( const Incidence::Ptr &incidence )
{
if ( !QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.korganizer" ) ) {
if ( KToolInvocation::startServiceByDesktopName( "korganizer", QString() ) ) {
KMessageBox::error(
this,
i18nc( "@info",
"Could not start KOrganizer so editing is not possible." ) );
return false;
}
}
org::kde::korganizer::Korganizer korganizer(
"org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() );
kDebug() << "editing incidence " << incidence->summary();
if ( !korganizer.editIncidence( incidence->uid() ) ) {
KMessageBox::error(
this,
i18nc( "@info",
"An internal KOrganizer error occurred attempting to modify \"%1\"",
cleanSummary( incidence->summary() ) ) );
}
// get desktop # where korganizer (or kontact) runs
QString object =
QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.kontact" ) ?
"kontact/MainWindow_1" : "korganizer/MainWindow_1";
QDBusInterface korganizerObj( "org.kde.korganizer", '/' + object );
#ifdef Q_WS_X11
QDBusReply<int> reply = korganizerObj.call( "winId" );
if ( reply.isValid() ) {
int window = reply;
int desktop = KWindowSystem::windowInfo( window, NET::WMDesktop ).desktop();
if ( KWindowSystem::currentDesktop() == desktop ) {
KWindowSystem::minimizeWindow( winId(), false );
} else {
KWindowSystem::setCurrentDesktop( desktop );
}
KWindowSystem::activateWindow( KWindowSystem::transientFor( window ) );
}
#elif defined(Q_WS_WIN)
// WId is a typedef to a void* on windows
QDBusReply<qlonglong> reply = korganizerObj.call( "winId" );
if ( reply.isValid() ) {
qlonglong window = reply;
KWindowSystem::minimizeWindow( winId(), false );
KWindowSystem::allowExternalProcessWindowActivation();
KWindowSystem::activateWindow( reinterpret_cast<WId>(window) );
}
#else
// TODO (mac)
#endif
return true;
}
#include "alarmdialog.moc"
......@@ -101,6 +101,7 @@ class AlarmDialog : public KDialog
static KDateTime triggerDateForIncidence( const KCalCore::Incidence::Ptr &inc,
const QDateTime &reminderAt,
QString &displayStr );
bool openEditorThroughKOrganizer( const KCalCore::Incidence::Ptr &incidence );
bool startKOrganizer();
ReminderListItem *searchByItem( const Akonadi::Item &incidence );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment