Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/widget/wlibrary.cpp

Go to the documentation of this file.
00001 // wlibrary.cpp
00002 // Created 8/28/2009 by RJ Ryan (rryan@mit.edu)
00003 
00004 #include <QtDebug>
00005 #include <QMutexLocker>
00006 
00007 #include "widget/wlibrary.h"
00008 #include "library/libraryview.h"
00009 #include "mixxxkeyboard.h"
00010 
00011 WLibrary::WLibrary(QWidget* parent)
00012         : QStackedWidget(parent),
00013           m_mutex(QMutex::Recursive) {
00014 }
00015 
00016 WLibrary::~WLibrary() {
00017 
00018 }
00019 
00020 bool WLibrary::registerView(QString name, QWidget* view) {
00021     QMutexLocker lock(&m_mutex);
00022     if (m_viewMap.contains(name)) {
00023         return false;
00024     }
00025     if (dynamic_cast<LibraryView*>(view) == NULL) {
00026         qDebug() << "WARNING: Attempted to register a view with WLibrary that does not implement the LibraryView interface. Ignoring.";
00027         return false;
00028     }
00029     addWidget(view);
00030     m_viewMap[name] = view;
00031     return true;
00032 }
00033 
00034 void WLibrary::setup(QDomNode node) {
00035     QMutexLocker lock(&m_mutex);
00036     QListIterator<QWidget*> views_it(m_viewMap.values());
00037 
00038     while(views_it.hasNext()) {
00039         QWidget* widget = views_it.next();
00040         dynamic_cast<LibraryView*>(widget)->setup(node);
00041     }
00042 }
00043 
00044 void WLibrary::switchToView(const QString& name) {
00045     QMutexLocker lock(&m_mutex);
00046     //qDebug() << "WLibrary::switchToView" << name;
00047     if (m_viewMap.contains(name)) {
00048         QWidget* widget = m_viewMap[name];
00049         if (widget != NULL && currentWidget() != widget) {
00050             //qDebug() << "WLibrary::setCurrentWidget" << name;
00051             setCurrentWidget(widget);
00052             dynamic_cast<LibraryView*>(widget)->onShow();
00053         }
00054     }
00055 }
00056 
00057 void WLibrary::search(const QString& name) {
00058     QMutexLocker lock(&m_mutex);
00059     QWidget* current = currentWidget();
00060     LibraryView* view = dynamic_cast<LibraryView*>(current);
00061     lock.unlock();
00062     view->onSearch(name);
00063 }
00064 
00065 void WLibrary::searchCleared() {
00066     QMutexLocker lock(&m_mutex);
00067     QWidget* current = currentWidget();
00068     LibraryView* view = dynamic_cast<LibraryView*>(current);
00069     lock.unlock();
00070     view->onSearchCleared();
00071 }
00072 
00073 void WLibrary::searchStarting() {
00074     QMutexLocker lock(&m_mutex);
00075     QWidget* current = currentWidget();
00076     LibraryView* view = dynamic_cast<LibraryView*>(current);
00077     lock.unlock();
00078     view->onSearchStarting();
00079 }
00080 
00081 LibraryView* WLibrary::getActiveView() const {
00082     return dynamic_cast<LibraryView*>(currentWidget());
00083 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines