| Home · All Namespaces · All Classes |
00001 /*************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of mhome. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 00020 #include "quicklaunchbar.h" 00021 #include "launcherdatastore.h" 00022 #include "launcherbutton.h" 00023 #include "applicationpackagemonitorlistener.h" 00024 #include <MDesktopEntry> 00025 00026 #include <MWidgetCreator> 00027 M_REGISTER_WIDGET(QuickLaunchBar) 00028 00029 const int QuickLaunchBar::NUMBER_OF_LAUNCHER_BUTTONS = 4; 00030 const QString QuickLaunchBar::LOCATION_IDENTIFIER = "quicklaunchbar"; 00031 const char QuickLaunchBar::SECTION_SEPARATOR = '/'; 00032 00033 QuickLaunchBar::QuickLaunchBar(QGraphicsItem *parent) : 00034 MWidgetController(new QuickLaunchBarModel, parent), 00035 dataStore(NULL) 00036 { 00037 } 00038 00039 QuickLaunchBar::~QuickLaunchBar() 00040 { 00041 } 00042 00043 void QuickLaunchBar::setLauncherDataStore(LauncherDataStore *dataStore) 00044 { 00045 if (this->dataStore != NULL) { 00046 disconnect(dataStore, SIGNAL(dataStoreChanged()), this, SLOT(updateButtons())); 00047 } 00048 this->dataStore = dataStore; 00049 connect(dataStore, SIGNAL(dataStoreChanged()), this, SLOT(updateButtons())); 00050 } 00051 00052 void QuickLaunchBar::setApplicationPackageMonitorListener(ApplicationPackageMonitorListener *packageMonitorListener) 00053 { 00054 this->packageMonitorListener = packageMonitorListener; 00055 00056 connect(packageMonitorListener, SIGNAL(packageStateChanged(QString, LauncherButtonModel::State, int)), 00057 this, SLOT(updateButtonState(QString, LauncherButtonModel::State, int))); 00058 } 00059 00060 void QuickLaunchBar::updateButtonState(const QString &desktopEntryPath, LauncherButtonModel::State state, int progress) 00061 { 00062 //If there is a quicklaunch button for desktopEntryPath, update it's state 00063 QList<QSharedPointer<LauncherButton> > buttons = model()->buttons().values(); 00064 QString entryFileName = QFileInfo(desktopEntryPath).fileName(); 00065 for (int i = 0 ; i < buttons.count() ; i++) { 00066 if (QFileInfo(buttons.at(i)->desktopEntry()).fileName() == entryFileName) { 00067 buttons.at(i)->setState(state, progress, desktopEntryPath); 00068 } 00069 } 00070 } 00071 00072 void QuickLaunchBar::updateButtons() 00073 { 00074 if (dataStore == NULL) { 00075 return; 00076 } 00077 00078 // Temporarily disable the listening of the change signals from the configuration to prevent a recursive call to this method 00079 dataStore->disconnect(this); 00080 00081 // Construct a map of buttons and their positions 00082 QMap< int, QSharedPointer<LauncherButton> > newButtons; 00083 00084 // Add the desktop entries with known placements to the map 00085 QMapIterator<Placement, QString> iterator(createPlacementMap(dataStore->dataForAllDesktopEntries())); 00086 while (iterator.hasNext()) { 00087 iterator.next(); 00088 Placement placement(iterator.key()); 00089 QString desktopEntryPath(iterator.value()); 00090 newButtons.insert(placement.position, QSharedPointer<LauncherButton>(createLauncherButton(desktopEntryPath))); 00091 } 00092 00093 // Take the new buttons into use 00094 model()->setButtons(newButtons); 00095 00096 // Reconnect signals 00097 connect(dataStore, SIGNAL(dataStoreChanged()), this, SLOT(updateButtons())); 00098 } 00099 00100 LauncherButton *QuickLaunchBar::createLauncherButton(const QString &desktopEntryPath) 00101 { 00102 LauncherButton *button = new LauncherButton(desktopEntryPath); 00103 button->setObjectName("QuickLaunchBarButton"); 00104 return button; 00105 } 00106 00107 QMap<QuickLaunchBar::Placement, QString> QuickLaunchBar::createPlacementMap(const QHash<QString, QVariant> &desktopEntryPlacements) 00108 { 00109 QMap<QuickLaunchBar::Placement, QString> placementMap; 00110 00111 foreach (const QString &desktopEntryPath, desktopEntryPlacements.keys()) { 00112 Placement placement(desktopEntryPlacements.value(desktopEntryPath).toString()); 00113 if (placement.position >= 0) { 00114 placementMap.insert(placement, desktopEntryPath); 00115 } 00116 } 00117 00118 return placementMap; 00119 } 00120 00121 QuickLaunchBar::Placement::Placement(const QString &placement) : position(-1) { 00122 if (placement.section(SECTION_SEPARATOR, 0, 0) == LOCATION_IDENTIFIER) { 00123 position = placement.section(SECTION_SEPARATOR, 1, 1).toInt(); 00124 } 00125 } 00126 00127 inline bool operator<(const QuickLaunchBar::Placement &p1, const QuickLaunchBar::Placement &p2) 00128 { 00129 return p1.position < p2.position; 00130 }
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:20:42 Doxygen 1.7.1 |
MeeGo Touch |