diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2016-11-07 23:30:39 +0000 |
|---|---|---|
| committer | Bileto Bot <ci-train-bot@canonical.com> | 2016-11-07 23:30:39 +0000 |
| commit | 49507cb81973c527c9f0557e0a383979b29f2e21 (patch) | |
| tree | 83e5247ff55b5978ff05dc60fb9327e2be06a16a | |
| parent | 2ec321b4b275d958baa73e9ed126a9073178b745 (diff) | |
| parent | 1ef8178ea904b9fb6e465682cc4036e68284875f (diff) | |
Properly handle the file manager copy dialog in FileManagerLauncherIcon and in StorageLauncherIcon. (LP: #1575452, #1609845)
Approved by: Marco Trevisan (TreviƱo) (bzr r4202)
| -rw-r--r-- | launcher/FileManagerLauncherIcon.cpp | 30 | ||||
| -rw-r--r-- | launcher/FileManagerLauncherIcon.h | 8 | ||||
| -rw-r--r-- | launcher/StorageLauncherIcon.cpp | 19 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/test_file_manager_launcher_icon.cpp | 202 |
5 files changed, 248 insertions, 12 deletions
diff --git a/launcher/FileManagerLauncherIcon.cpp b/launcher/FileManagerLauncherIcon.cpp index 3fabb7adb..0926997fe 100644 --- a/launcher/FileManagerLauncherIcon.cpp +++ b/launcher/FileManagerLauncherIcon.cpp @@ -49,6 +49,11 @@ FileManagerLauncherIcon::FileManagerLauncherIcon(ApplicationPtr const& app, Devi SetQuirk(Quirk::VISIBLE, false); SkipQuirkAnimation(Quirk::VISIBLE); + signals_conn_.Add(app_->window_opened.connect([this](ApplicationWindowPtr const& win) { + signals_conn_.Add(win->monitor.changed.connect([this] (int) { UpdateStorageWindows(); })); + UpdateStorageWindows(); + })); + signals_conn_.Add(app_->desktop_file.changed.connect([this](std::string const& desktop_file) { LOG_DEBUG(logger) << tooltip_text() << " desktop_file now " << desktop_file; UpdateDesktopFile(); @@ -134,5 +139,30 @@ bool FileManagerLauncherIcon::OnShouldHighlightOnDrag(DndData const& dnd_data) return StorageLauncherIcon::OnShouldHighlightOnDrag(dnd_data); } +bool FileManagerLauncherIcon::IsUserVisible() const +{ + return ApplicationLauncherIcon::IsUserVisible(); +} + +WindowList FileManagerLauncherIcon::WindowsOnViewport() +{ + WindowFilterMask filter = 0; + filter |= WindowFilter::MAPPED; + filter |= WindowFilter::ON_CURRENT_DESKTOP; + filter |= WindowFilter::ON_ALL_MONITORS; + + return WindowedLauncherIcon::GetWindows(filter); +} + +WindowList FileManagerLauncherIcon::WindowsForMonitor(int monitor) +{ + WindowFilterMask filter = 0; + filter |= WindowFilter::MAPPED; + filter |= WindowFilter::ON_CURRENT_DESKTOP; + + return WindowedLauncherIcon::GetWindows(filter, monitor); +} + + } // namespace launcher } // namespace unity diff --git a/launcher/FileManagerLauncherIcon.h b/launcher/FileManagerLauncherIcon.h index 1996747a3..3b7d5d466 100644 --- a/launcher/FileManagerLauncherIcon.h +++ b/launcher/FileManagerLauncherIcon.h @@ -32,8 +32,16 @@ namespace launcher class FileManagerLauncherIcon : public ApplicationLauncherIcon, public StorageLauncherIcon { public: + typedef nux::ObjectPtr<FileManagerLauncherIcon> Ptr; + FileManagerLauncherIcon(ApplicationPtr const&, DeviceLauncherSection::Ptr const&, FileManager::Ptr const& = nullptr); + bool IsUserVisible() const override; + +protected: + WindowList WindowsOnViewport() override; + WindowList WindowsForMonitor(int monitor) override; + private: WindowList GetManagedWindows() const override; WindowList GetStorageWindows() const override; diff --git a/launcher/StorageLauncherIcon.cpp b/launcher/StorageLauncherIcon.cpp index fcc367b72..fcd50c54d 100644 --- a/launcher/StorageLauncherIcon.cpp +++ b/launcher/StorageLauncherIcon.cpp @@ -36,7 +36,7 @@ void StorageLauncherIcon::UpdateStorageWindows() bool active = false; bool urgent = false; bool check_visibility = (GetIconType() == IconType::APPLICATION); - bool visible = IsSticky(); + bool visible = false; managed_windows_ = GetStorageWindows(); windows_connections_.Clear(); @@ -54,13 +54,8 @@ void StorageLauncherIcon::UpdateStorageWindows() if (!urgent && win->urgent()) urgent = true; - if (check_visibility) - { - windows_connections_.Add(win->visible.changed.connect([this] (bool) { OnWindowStateChanged(); })); - - if (!visible && win->visible()) - visible = true; - } + if (check_visibility && !visible) + visible = true; } SetQuirk(Quirk::RUNNING, !managed_windows_.empty()); @@ -68,7 +63,7 @@ void StorageLauncherIcon::UpdateStorageWindows() SetQuirk(Quirk::URGENT, urgent); if (check_visibility) - SetQuirk(Quirk::VISIBLE, visible); + SetQuirk(Quirk::VISIBLE, visible || IsSticky()); EnsureWindowsLocation(); } @@ -83,7 +78,7 @@ void StorageLauncherIcon::OnWindowStateChanged() bool active = false; bool urgent = false; bool check_visibility = (GetIconType() == IconType::APPLICATION); - bool visible = IsSticky(); + bool visible = false; for (auto const& win : managed_windows_) { @@ -93,7 +88,7 @@ void StorageLauncherIcon::OnWindowStateChanged() if (!urgent && win->urgent()) urgent = true; - if (check_visibility && !visible && win->visible()) + if (check_visibility && !visible) visible = true; } @@ -101,7 +96,7 @@ void StorageLauncherIcon::OnWindowStateChanged() SetQuirk(Quirk::URGENT, urgent); if (check_visibility) - SetQuirk(Quirk::VISIBLE, visible); + SetQuirk(Quirk::VISIBLE, visible || IsSticky()); } bool StorageLauncherIcon::OnShouldHighlightOnDrag(DndData const& dnd_data) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4d949ae50..a19a1512d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -224,6 +224,7 @@ if (ENABLE_X_SUPPORT) test_error_preview.cpp test_edge_barrier_controller.cpp test_expo_launcher_icon.cpp + test_file_manager_launcher_icon.cpp test_filter_widgets.cpp test_glib_dbus_server.cpp test_gnome_session_manager.cpp diff --git a/tests/test_file_manager_launcher_icon.cpp b/tests/test_file_manager_launcher_icon.cpp new file mode 100644 index 000000000..fe1471ec2 --- /dev/null +++ b/tests/test_file_manager_launcher_icon.cpp @@ -0,0 +1,202 @@ +/* + * Copyright 2016 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY 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 + * version 3 along with this program. If not, see + * <http://www.gnu.org/licenses/> + * + * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> + */ + +#include <gmock/gmock.h> +using namespace testing; + +#include "FileManagerLauncherIcon.h" +#include "UnityCore/DesktopUtilities.h" + +#include "test_mock_devices.h" +#include "test_mock_filemanager.h" +#include "mock-application.h" + +using namespace unity; +using namespace unity::launcher; +using namespace testmocks; + +namespace +{ + +const std::string TRASH_URI = "trash:"; +const std::string TRASH_PATH = "file://" + DesktopUtilities::GetUserTrashDirectory(); + +struct TestFileManagerLauncherIcon : public Test +{ + TestFileManagerLauncherIcon() + : app_(std::make_shared<MockApplication::Nice>()) + , fm_(std::make_shared<MockFileManager::Nice>()) + , dev_ (std::make_shared<MockDeviceLauncherSection>(2)) + , icon_(new FileManagerLauncherIcon(app_, dev_, fm_)) + { + } + + MockApplication::Ptr app_; + MockFileManager::Ptr fm_; + DeviceLauncherSection::Ptr dev_; + FileManagerLauncherIcon::Ptr icon_; +}; + +TEST_F(TestFileManagerLauncherIcon, IconType) +{ + EXPECT_EQ(icon_->GetIconType(), AbstractLauncherIcon::IconType::APPLICATION); +} + +TEST_F(TestFileManagerLauncherIcon, NoWindow) +{ + EXPECT_FALSE(icon_->IsVisible()); +} + +TEST_F(TestFileManagerLauncherIcon, NoManagedWindow_TrashUri) +{ + EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1); + ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(TRASH_URI)); + + auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + app_->windows_ = { win }; + app_->window_opened.emit(win); + + EXPECT_FALSE(icon_->IsVisible()); + EXPECT_FALSE(icon_->IsRunning()); +} + +TEST_F(TestFileManagerLauncherIcon, NoManagedWindow_TrashPath) +{ + EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1); + ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(TRASH_PATH)); + + auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + app_->windows_ = { win }; + app_->window_opened.emit(win); + + EXPECT_FALSE(icon_->IsVisible()); + EXPECT_FALSE(icon_->IsRunning()); +} + +TEST_F(TestFileManagerLauncherIcon, NoManagedWindow_Device) +{ + auto const& device_icons = dev_->GetIcons(); + ASSERT_EQ(2, device_icons.size()); + + device_icons.at(0)->Activate(ActionArg()); + + EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1); + ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(device_icons.at(0)->GetVolumeUri())); + + auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + app_->windows_ = { win }; + app_->window_opened.emit(win); + + EXPECT_FALSE(icon_->IsVisible()); + EXPECT_FALSE(icon_->IsRunning()); +} + +TEST_F(TestFileManagerLauncherIcon, ManagedWindows) +{ + EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1); + ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return("/usr/bin")); + + auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + app_->windows_ = { win }; + app_->window_opened.emit(win); + + EXPECT_TRUE(icon_->IsVisible()); + EXPECT_TRUE(icon_->IsRunning()); +} + +TEST_F(TestFileManagerLauncherIcon, ManagedWindows_EmptyLocation) +{ + EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1); + ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return("")); + + auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + app_->windows_ = { win }; + app_->window_opened.emit(win); + + EXPECT_TRUE(icon_->IsVisible()); + EXPECT_TRUE(icon_->IsRunning()); +} + +TEST_F(TestFileManagerLauncherIcon, ManagedWindows_CopyDialog) +{ + EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1); + ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return("")); + + auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + win->visible_ = false; + app_->windows_ = { win }; + app_->window_opened.emit(win); + + EXPECT_TRUE(icon_->IsVisible()); + EXPECT_TRUE(icon_->IsRunning()); +} + + +TEST_F(TestFileManagerLauncherIcon, ManagedWindows_CopyDialogAndManagedWindow) +{ + EXPECT_CALL(*fm_, LocationForWindow(_)).Times(3); + ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return("")); + + auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + app_->windows_ = { win }; + app_->window_opened.emit(win); + + win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + win->visible_ = false; + app_->windows_.push_back(win); + app_->window_opened.emit(win); + + EXPECT_TRUE(icon_->IsVisible()); + EXPECT_TRUE(icon_->IsRunning()); + EXPECT_EQ(2, icon_->WindowsVisibleOnMonitor(0)); +} + +TEST_F(TestFileManagerLauncherIcon, ManagedWindows_CopyDialogAndNoManagedWindow) +{ + { + InSequence s; + + EXPECT_CALL(*fm_, LocationForWindow(_)) + .Times(1) + .WillOnce(Return("")); + + EXPECT_CALL(*fm_, LocationForWindow(_)) + .Times(1) + .WillOnce(Return("")); + + EXPECT_CALL(*fm_, LocationForWindow(_)) + .Times(1) + .WillOnce(Return(TRASH_PATH)); + } + + auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + app_->windows_ = { win }; + app_->window_opened.emit(win); + + win = std::make_shared<MockApplicationWindow::Nice>(g_random_int()); + win->visible_ = false; + app_->windows_.push_back(win); + app_->window_opened.emit(win); + + EXPECT_TRUE(icon_->IsVisible()); + EXPECT_TRUE(icon_->IsRunning()); + EXPECT_EQ(1, icon_->WindowsVisibleOnMonitor(0)); +} + +} |
