~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/FavoriteStorePrivate.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
 
2
/*
 
3
* Copyright (C) 2011 Canonical Ltd
 
4
*
 
5
* This program is free software: you can redistribute it and/or modify
 
6
* it under the terms of the GNU General Public License version 3 as
 
7
* published by the Free Software Foundation.
 
8
*
 
9
* This program is distributed in the hope that it will be useful,
 
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
* GNU General Public License for more details.
 
13
*
 
14
* You should have received a copy of the GNU General Public License
 
15
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
*
 
17
* Authored by: Andrea Azzaronea <azzaronea@gmail.com>
 
18
*/
 
19
 
 
20
#include <algorithm>
 
21
#include <boost/utility.hpp>
 
22
 
 
23
#include "FavoriteStorePrivate.h"
 
24
 
 
25
namespace unity
 
26
{
 
27
namespace internal
 
28
{
 
29
namespace impl
 
30
{
 
31
 
 
32
std::vector<std::string> GetNewbies(std::list<std::string> const& old, std::list<std::string> const& fresh)
 
33
{
 
34
  auto sorted_old(old);
 
35
  auto sorted_fresh(fresh);
 
36
 
 
37
  sorted_old.sort();
 
38
  sorted_fresh.sort();
 
39
 
 
40
  std::vector<std::string> result;
 
41
  std::set_difference(sorted_fresh.begin(), sorted_fresh.end(), sorted_old.begin(), sorted_old.end(),
 
42
                      std::inserter(result, result.end()));
 
43
 
 
44
  return result;
 
45
}
 
46
 
 
47
void GetSignalAddedInfo(std::list<std::string> const& favs, std::vector<std::string> const& newbies,
 
48
                        std::string const& path, std::string& position, bool& before)
 
49
{
 
50
  auto it = std::find(favs.begin(), favs.end(), path);
 
51
  before = (it == favs.begin());
 
52
  position = "";
 
53
 
 
54
  if (before and favs.size() > 1)
 
55
  {
 
56
    while (it != favs.end() && std::find(newbies.begin(), newbies.end(), *it) != newbies.end())
 
57
      ++it;
 
58
 
 
59
    if (it != favs.end())
 
60
      position = *it;
 
61
  }
 
62
  else if (!before)
 
63
  {
 
64
    position = *(boost::prior(it));
 
65
  }
 
66
 
 
67
}
 
68
 
 
69
std::vector<std::string> GetRemoved(std::list<std::string> const& old, std::list<std::string> const& fresh)
 
70
{
 
71
  auto sorted_old(old);
 
72
  auto sorted_fresh(fresh);
 
73
 
 
74
  sorted_old.sort();
 
75
  sorted_fresh.sort();
 
76
 
 
77
  std::vector<std::string> result;
 
78
  std::set_difference(sorted_old.begin(), sorted_old.end(), sorted_fresh.begin(), sorted_fresh.end(),
 
79
                      std::inserter(result, result.end()));
 
80
 
 
81
  return result;
 
82
}
 
83
 
 
84
 
 
85
bool NeedToBeReordered(std::list<std::string> const& old, std::list<std::string> const& fresh)
 
86
{
 
87
  auto sorted_old(old);
 
88
  auto sorted_fresh(fresh);
 
89
 
 
90
  sorted_old.sort();
 
91
  sorted_fresh.sort();
 
92
 
 
93
  std::vector<std::string> ignore_old, ignore_fresh;
 
94
 
 
95
  std::set_difference(sorted_old.begin(), sorted_old.end(), sorted_fresh.begin(), sorted_fresh.end(),
 
96
                      std::inserter(ignore_old, ignore_old.end()));
 
97
  std::set_difference(sorted_fresh.begin(), sorted_fresh.end(), sorted_old.begin(), sorted_old.end(),
 
98
                      std::inserter(ignore_fresh, ignore_fresh.end()));
 
99
 
 
100
  auto it_old = old.begin();
 
101
  auto it_fresh = fresh.begin();
 
102
 
 
103
  while (it_old != old.end() && it_fresh != fresh.end())
 
104
  {
 
105
 
 
106
    while (it_old != old.end() && std::find(ignore_old.begin(), ignore_old.end(), *it_old) != ignore_old.end())
 
107
      ++it_old;
 
108
 
 
109
    while (it_fresh != fresh.end() && std::find(ignore_fresh.begin(), ignore_fresh.end(), *it_fresh) != ignore_fresh.end())
 
110
      ++it_fresh;
 
111
 
 
112
    if (it_old == old.end() || it_fresh == fresh.end())
 
113
      break;
 
114
 
 
115
    if (*it_old != *it_fresh)
 
116
    {
 
117
      return true;
 
118
    }
 
119
 
 
120
    ++it_old;
 
121
    ++it_fresh;
 
122
  }
 
123
 
 
124
  return false;
 
125
}
 
126
 
 
127
 
 
128
} // namespace impl
 
129
} // namespace internal
 
130
} // namespace unity