Bug 247263 - Konversation lacks a shortcut to Toggle Main Window
Summary: Konversation lacks a shortcut to Toggle Main Window
Status: RESOLVED FIXED
Alias: None
Product: konversation
Classification: Applications
Component: general (show other bugs)
Version: 1.2.3
Platform: Unlisted Binaries Linux
: NOR wishlist
Target Milestone: ---
Assignee: Konversation Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-10 17:57 UTC by Adrián Chaves (Gallaecio)
Modified: 2010-08-10 21:53 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adrián Chaves (Gallaecio) 2010-08-10 17:57:37 UTC
Version:           1.2.3 (using KDE 4.5.0) 
OS:                Linux

This is something I really miss. It's a feature I saw in apps like Ktorrent and Amarok, that I can toggle whenever I want with a global shortcut. I would like to be able to do the same with Konversation.

Reproducible: Always

Steps to Reproduce:
Go to Konversation shortcuts configuration.

Actual Results:  
See no Toggle Main Window or similar entry.

Expected Results:  
See a Toggle Main Window or similar entry.
Comment 1 Adrián Chaves (Gallaecio) 2010-08-10 18:14:31 UTC
Deeply sorry about the multiple reports. I though the data was not being sended since it was loading pretty slow (must have been my network connection). :S
Comment 2 Eike Hein 2010-08-10 21:32:28 UTC
commit 1e59b7b1a41ba268ca27c332d6d384c1acfc4493
Author: Eike Hein <hein@kde.org>
Date:   Tue Aug 10 21:32:25 2010 +0200

    Add an action to show/hide the main window.
    
    BUG:247263

diff --git a/ChangeLog b/ChangeLog
index 0eb8e89..ffe288a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -117,6 +117,9 @@ Changes since 1.3.1:
   - Average spreed of link detection has improved slightly.
 * Incoming actions (i.e. "/me") without an argument are now handled properly.
 * Fixed a number of crashes on illegal data from the server.
+* Added a "Show/Hide Konversation" action that can be used to toggle the
+  minimized state of the Konversation window or, if the tray icon is enabled,
+  its visibility.
 
 
 Changes from 1.3 to 1.3.1:
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 35e16c7..caf8b32 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -486,6 +486,12 @@ MainWindow::MainWindow() : KXmlGuiWindow(0)
     connect(toggleChannelNickListsAction, SIGNAL(triggered()), m_viewContainer, SLOT(toggleChannelNicklists()));
     actionCollection()->addAction("hide_nicknamelist", toggleChannelNickListsAction);
 
+    action=new KAction(this);
+    action->setText(i18n("Show/Hide Konversation"));
+    connect(action, SIGNAL(triggered()), this, SLOT(toggleVisibility()));
+    actionCollection()->addAction("toggle_mainwindow_visibility", action);
+    action->setGlobalShortcut(KShortcut());
+
     // Bookmarks
     KActionMenu *bookmarkMenu = new KActionMenu(i18n("Bookmarks"), actionCollection());
     new KonviBookmarkHandler(bookmarkMenu->menu(), this);
@@ -844,4 +850,22 @@ void MainWindow::setOnlineList(Server* notifyServer,const QStringList& /*list*/,
     // FIXME  if (changed && nicksOnlinePanel) newText(nicksOnlinePanel, QString::null, true);
 }
 
+void MainWindow::toggleVisibility()
+{
+    if (isMinimized())
+    {
+        KWindowSystem::unminimizeWindow(winId());
+        KWindowSystem::activateWindow(winId());
+    }
+    else if (isVisible())
+    {
+        if (Preferences::self()->showTrayIcon())
+            hide();
+        else
+            KWindowSystem::minimizeWindow(winId());
+    }
+    else if (Preferences::self()->showTrayIcon())
+        m_trayIcon->restore();
+}
+
 #include "mainwindow.moc"
diff --git a/src/mainwindow.h b/src/mainwindow.h
index cac6526..8cff7ba 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -109,6 +109,8 @@ class MainWindow : public KXmlGuiWindow
         void openNotifications();
         void notifyAction(int connectionId,const QString& nick);
 
+        void toggleVisibility();
+
         void showEvent(QShowEvent* e);
         void hideEvent(QHideEvent* e);
         void leaveEvent(QEvent* e);
diff --git a/src/viewer/trayicon.h b/src/viewer/trayicon.h
index de99b05..418868d 100644
--- a/src/viewer/trayicon.h
+++ b/src/viewer/trayicon.h
@@ -34,13 +34,15 @@ namespace Konversation
 #endif
     {
         Q_OBJECT
-        
+
         public:
             explicit TrayIcon(QWidget* parent = 0);
             ~TrayIcon();
 
             bool notificationEnabled() { return m_notificationEnabled; }
 
+            void restore();
+
         public slots:
             void startNotification();
             void endNotification();
diff --git a/src/viewer/trayiconkstatusnotifieritem.cpp b/src/viewer/trayiconkstatusnotifieritem.cpp
index 250c005..9982e18 100644
--- a/src/viewer/trayiconkstatusnotifieritem.cpp
+++ b/src/viewer/trayiconkstatusnotifieritem.cpp
@@ -18,7 +18,7 @@ namespace Konversation
         setStatus(Active);
 
         m_notificationEnabled = false;
-        
+
         updateAppearance();
 
         setToolTip("konversation", i18n("Konversation"), i18n("Konversation - IRC Client"));
@@ -28,6 +28,11 @@ namespace Konversation
     {
     }
 
+    void TrayIcon::restore()
+    {
+        activate(QPoint());
+    }
+
     void TrayIcon::startNotification()
     {
         if (!m_notificationEnabled)
@@ -42,12 +47,12 @@ namespace Konversation
     {
         setStatus(Active);
     }
-    
+
     void TrayIcon::updateAppearance()
     {
         m_nomessagePix = "konversation";
         m_messagePix = "konv_message";
-        
+
         setIconByName(m_nomessagePix);
         setAttentionIconByName(m_messagePix);
     }
diff --git a/src/viewer/trayiconksystemtray.cpp b/src/viewer/trayiconksystemtray.cpp
index f72e389..4b60381 100644
--- a/src/viewer/trayiconksystemtray.cpp
+++ b/src/viewer/trayiconksystemtray.cpp
@@ -38,6 +38,11 @@ namespace Konversation
     {
     }
 
+    void TrayIcon::restore()
+    {
+        toggleActive();
+    }
+
     void TrayIcon::startNotification()
     {
         if(!m_notificationEnabled)
@@ -80,13 +85,13 @@ namespace Konversation
             setIcon(m_nomessagePix);
         }
     }
-    
+
     void TrayIcon::updateAppearance()
     {
         m_nomessagePix = loadIcon("konversation");
         m_messagePix = loadIcon("konv_message");
         setIcon(m_nomessagePix);
-        
+
         show();
     }
 }
Comment 3 Eike Hein 2010-08-10 21:36:51 UTC
commit 1ab55d2b294b43e54c65fe1868e947ca5dc62946
Author: Eike Hein <hein@kde.org>
Date:   Tue Aug 10 21:36:55 2010 +0200

    Pull to current desktop on show by action.
    
    CCBUG:247263

diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index caf8b32..8dc435e 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -855,6 +855,7 @@ void MainWindow::toggleVisibility()
     if (isMinimized())
     {
         KWindowSystem::unminimizeWindow(winId());
+        KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
         KWindowSystem::activateWindow(winId());
     }
     else if (isVisible())
@@ -865,7 +866,10 @@ void MainWindow::toggleVisibility()
             KWindowSystem::minimizeWindow(winId());
     }
     else if (Preferences::self()->showTrayIcon())
+    {
+        KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
         m_trayIcon->restore();
+    }
 }
 
 #include "mainwindow.moc"
Comment 4 Adrián Chaves (Gallaecio) 2010-08-10 21:38:56 UTC
That was really fast. Thanks a lot.
Comment 5 Eike Hein 2010-08-10 21:49:26 UTC
commit 65f91b9e833dc40e0b3e093dec06d173f9929afa
Author: Eike Hein <hein@kde.org>
Date:   Tue Aug 10 21:49:21 2010 +0200

    Handle another scenario.
    
    BUG:247263

diff --git a/ChangeLog b/ChangeLog
index ffe288a..c500b5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -119,7 +119,10 @@ Changes since 1.3.1:
 * Fixed a number of crashes on illegal data from the server.
 * Added a "Show/Hide Konversation" action that can be used to toggle the
   minimized state of the Konversation window or, if the tray icon is enabled,
-  its visibility.
+  its visibility. Additionally, the window will always be moved to the
+  current virtual desktop if shown using this action (if the window is
+  already shown on another desktop, it will be moved to the current desktop
+  rather than hidden).
 
 
 Changes from 1.3 to 1.3.1:
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 8dc435e..ec2f5a6 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -860,10 +860,20 @@ void MainWindow::toggleVisibility()
     }
     else if (isVisible())
     {
-        if (Preferences::self()->showTrayIcon())
-            hide();
+        bool onCurrentDesktop = KWindowSystem::windowInfo(winId(), NET::WMDesktop).isOnCurrentDesktop();
+
+        if (onCurrentDesktop)
+        {
+            if (Preferences::self()->showTrayIcon())
+                hide();
+            else
+                KWindowSystem::minimizeWindow(winId());
+        }
         else
-            KWindowSystem::minimizeWindow(winId());
+        {
+            KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
+            KWindowSystem::activateWindow(winId());
+        }
     }
     else if (Preferences::self()->showTrayIcon())
     {
Comment 6 Eike Hein 2010-08-10 21:53:53 UTC
No problem - and don't worry about the duplicate reports, it was probably the server's fault (high load due to the 4.5.0 release today).