Back to index

unity  6.0.0
QuicklistManager.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Jamal Fanaian <j@jamalfanaian.com>
00018  */
00019 
00020 #include <Nux/Nux.h>
00021 #include <Nux/BaseWindow.h>
00022 #include <Nux/VLayout.h>
00023 #include <Nux/WindowCompositor.h>
00024 
00025 #include "QuicklistView.h"
00026 #include "QuicklistManager.h"
00027 
00028 #include "unity-shared/ubus-server.h"
00029 #include "unity-shared/UBusMessages.h"
00030 
00031 namespace unity
00032 {
00033 
00034 QuicklistManager* QuicklistManager::_default = 0;
00035 
00036 /* static */
00037 QuicklistManager* QuicklistManager::Default()
00038 {
00039   if (!_default)
00040     _default = new QuicklistManager();
00041   return _default;
00042 }
00043 
00044 void QuicklistManager::Destroy()
00045 {
00046   delete _default;
00047   _default = 0;
00048 }
00049 
00050 QuicklistManager::QuicklistManager()
00051 {
00052   _current_quicklist = 0;
00053 }
00054 
00055 QuicklistManager::~QuicklistManager()
00056 {
00057 }
00058 
00059 QuicklistView* QuicklistManager::Current()
00060 {
00061   return _current_quicklist;
00062 }
00063 
00064 void QuicklistManager::RegisterQuicklist(QuicklistView* quicklist)
00065 {
00066   std::list<QuicklistView*>::iterator it;
00067 
00068   if (std::find(_quicklist_list.begin(), _quicklist_list.end(), quicklist) != _quicklist_list.end())
00069   {
00070     // quicklist has already been registered
00071     g_warning("Attempted to register a quicklist that was previously registered");
00072     return;
00073   }
00074 
00075   _quicklist_list.push_back(quicklist);
00076 
00077   quicklist->sigVisible.connect(sigc::mem_fun(this, &QuicklistManager::RecvShowQuicklist));
00078   quicklist->sigHidden.connect(sigc::mem_fun(this, &QuicklistManager::RecvHideQuicklist));
00079 }
00080 
00081 void QuicklistManager::ShowQuicklist(QuicklistView* quicklist, int tip_x,
00082                                      int tip_y, bool hide_existing_if_open)
00083 {
00084   if (_current_quicklist == quicklist)
00085   {
00086     // this quicklist is already active
00087     // do we want to still redraw in case the position has changed?
00088     return;
00089   }
00090 
00091   if (hide_existing_if_open && _current_quicklist)
00092   {
00093     HideQuicklist(_current_quicklist);
00094   }
00095 
00096   quicklist->ShowQuicklistWithTipAt(tip_x, tip_y);
00097   nux::GetWindowCompositor().SetKeyFocusArea(quicklist);
00098 }
00099 
00100 void QuicklistManager::HideQuicklist(QuicklistView* quicklist)
00101 {
00102   quicklist->Hide();
00103 }
00104 
00105 void QuicklistManager::RecvShowQuicklist(nux::BaseWindow* window)
00106 {
00107   QuicklistView* quicklist = (QuicklistView*) window;
00108 
00109   _current_quicklist = quicklist;
00110 
00111   quicklist_opened.emit(quicklist);
00112   UBusServer* ubus = ubus_server_get_default();
00113   ubus_server_send_message(ubus, UBUS_QUICKLIST_SHOWN, NULL);
00114 }
00115 
00116 void QuicklistManager::RecvHideQuicklist(nux::BaseWindow* window)
00117 {
00118   QuicklistView* quicklist = (QuicklistView*) window;
00119 
00120   if (_current_quicklist == quicklist)
00121   {
00122     _current_quicklist = 0;
00123   }
00124 
00125   quicklist_closed.emit(quicklist);
00126 }
00127 
00128 } // NAMESPACE