[Amarok] 2aecd99 added an interface that allows backend components

Maximilian Kossick maximilian.kossick at googlemail.com
Mon Apr 5 17:57:22 CEST 2010


	A	 src/core/interfaces/Logger.h	 [License: UNKNOWN]


	A	 src/core/interfaces/Logger.cpp	 [License: UNKNOWN]

commit 2aecd9953928f6533e36d9e6cab7588f98a97fd2
Author: Maximilian Kossick <maximilian.kossick at googlemail.com>
Date:   Mon Apr 5 17:56:24 2010 +0200

    added an interface that allows backend components to notify the user while hiding the actual implementation of the notification.
    Code should use the interface instead of StatusBar directly. That allows us to supply other implementations on different platforms.
    
    CCMAIL: amarok-devel at kde.org

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 29d6a6a..64f2acb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -270,6 +270,14 @@ set(libstatusbar_SRCS
 )
 
 #####################################################################
+# CORE INTERFACES
+#####################################################################
+set(core_interfaces_SRCS
+    core/interfaces/Logger.cpp
+)
+
+
+#####################################################################
 # META
 #####################################################################
 set(core_SRCS
@@ -615,6 +623,7 @@ set(amaroklib_LIB_SRCS
     ${libdynamic_SRCS}
     ${likeback_SRCS}
     ${core_SRCS}
+    ${core_interfaces_SRCS}
     ${apg_SRCS}
     ${collection_SRCS}
     ${mac_SRCS}
diff --git a/src/core/interfaces/Logger.cpp b/src/core/interfaces/Logger.cpp
new file mode 100644
index 0000000..6d4c333
--- /dev/null
+++ b/src/core/interfaces/Logger.cpp
@@ -0,0 +1,17 @@
+/****************************************************************************************
+ * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick at googlemail.com>            *
+ *                                                                                      *
+ * This program is free software; you can redistribute it and/or modify it under        *
+ * the terms of the GNU General Public License as published by the Free Software        *
+ * Foundation; either version 2 of the License, or (at your option) any later           *
+ * version.                                                                             *
+ *                                                                                      *
+ * This program 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 General Public License for more details.             *
+ *                                                                                      *
+ * You should have received a copy of the GNU General Public License along with         *
+ * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
+ ****************************************************************************************/
+
+#include "Logger.h"
diff --git a/src/core/interfaces/Logger.h b/src/core/interfaces/Logger.h
new file mode 100644
index 0000000..ab45040
--- /dev/null
+++ b/src/core/interfaces/Logger.h
@@ -0,0 +1,75 @@
+/****************************************************************************************
+ * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick at googlemail.com>            *
+ *                                                                                      *
+ * This program is free software; you can redistribute it and/or modify it under        *
+ * the terms of the GNU General Public License as published by the Free Software        *
+ * Foundation; either version 2 of the License, or (at your option) any later           *
+ * version.                                                                             *
+ *                                                                                      *
+ * This program 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 General Public License for more details.             *
+ *                                                                                      *
+ * You should have received a copy of the GNU General Public License along with         *
+ * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
+ ****************************************************************************************/
+
+#ifndef AMAROK_LOGGER_H
+#define AMAROK_LOGGER_H
+
+#include <QObject>
+
+class KJob;
+
+namespace Amarok
+{
+    /**
+      * This interface provides methods that allow backend components to notify the user.
+      * Users of this class may not make assumptions about the kind of notifications that
+      * will be sent to the user.
+      *
+      * The class name is up for discussion btw.
+      */
+    class Logger : public QObject
+    {
+        Q_OBJECT
+        Q_ENUMS( MessageType )
+    public:
+
+        enum MessageType { Information, Warning, Error };
+
+        Logger() {}
+        virtual ~Logger() {}
+
+    public slots:
+
+        /**
+          * Informs the user about the progress of a job, i.e. a download job.
+          * At the very least, the user is notified about the start and end of the job.
+          *
+          * @param job The job whose progress should be monitored
+          * @param text An additional text that will be part of the notification
+          * @param obj The object that will be called if the user cancels the job. If not set, the job will not be cancellable
+          * @param slot The slot on the given object that will be called if the user cancels the job. Not slot will be called if not set
+          */
+        virtual void newProgressOperation( KJob *job, const QString &text, QObject *obj = 0, const char *slot = 0 ) = 0;
+
+        /**
+          * Sends a notification to the user.
+          * This method will send a notification containing the given text to the user.
+          *
+          * @param text The text that the notification will contain
+          */
+        virtual void shortMessage( const QString &text ) = 0;
+
+        /**
+          * Send a notification to the user with an additional context.
+          * A notification will be send to the user containing the given text. Additionally, it will convey the context given by @p type.
+          * @param The text that the notification will contain
+          * @param The context of the notification
+          */
+        virtual void longMessage( const QString &text, MessageType type = Information ) = 0;
+    };
+}
+
+#endif
diff --git a/src/core/support/Components.cpp b/src/core/support/Components.cpp
index f9d144b..f508ad7 100644
--- a/src/core/support/Components.cpp
+++ b/src/core/support/Components.cpp
@@ -33,6 +33,7 @@ public:
     CollectionManager *collectionManager;
     EngineController *engineController;
     SqlStorage *sqlStorage;
+    Amarok::Logger *logger;
     Amarok::ApplicationController *applicationController;
     Collections::CollectionLocationDelegate *collectionLocationDelegate;
 };
@@ -64,6 +65,8 @@ COMPONENT_ACCESSORS( EngineController*, engineController, setEngineController )
 
 COMPONENT_ACCESSORS( SqlStorage*, sqlStorage, setSqlStorage )
 
+COMPONENT_ACCESSORS( Amarok::Logger*, logger, setLogger )
+
 COMPONENT_ACCESSORS( Amarok::ApplicationController*, applicationController, setApplicationController )
 
 COMPONENT_ACCESSORS( Collections::CollectionLocationDelegate*, collectionLocationDelegate, setCollectionLocationDelegate );
diff --git a/src/core/support/Components.h b/src/core/support/Components.h
index 042a0f6..d7b8a7e 100644
--- a/src/core/support/Components.h
+++ b/src/core/support/Components.h
@@ -22,6 +22,7 @@
 namespace Amarok
 {
     class ApplicationController;
+    class Logger;
 }
 
 namespace Collections
@@ -46,6 +47,9 @@ namespace Amarok
         AMAROK_EXPORT SqlStorage* sqlStorage();
         AMAROK_EXPORT SqlStorage* setSqlStorage( SqlStorage *storage );
 
+        AMAROK_EXPORT Amarok::Logger* logger();
+        AMAROK_EXPORT Amarok::Logger* setLogger( Amarok::Logger *logger );
+
         AMAROK_EXPORT Amarok::ApplicationController* applicationController();
         AMAROK_EXPORT Amarok::ApplicationController* setApplicationController( Amarok::ApplicationController *controller );
 


More information about the Amarok-devel mailing list