~lubuntu-dev/lxde/libfm-qt-debian-git

« back to all changes in this revision

Viewing changes to src/browsehistory.h

  • Committer: Alf Gaida
  • Date: 2015-12-17 15:45:00 UTC
  • Revision ID: git-v1:99d4cf5e0b3761023e2285ffb96a79d050f0bdf4
Tags: upstream/0.10.0+20151214
Adding upstream version 0.10.0+20151214.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 - 2015  Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library 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 GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 *
 
18
 */
 
19
 
 
20
 
 
21
#ifndef FM_BROWSEHISTORY_H
 
22
#define FM_BROWSEHISTORY_H
 
23
 
 
24
#include "libfmqtglobals.h"
 
25
#include <QVector>
 
26
#include <libfm/fm.h>
 
27
 
 
28
namespace Fm {
 
29
 
 
30
// class used to story browsing history of folder views
 
31
// We use this class to replace FmNavHistory provided by libfm since
 
32
// the original Libfm API is hard to use and confusing.
 
33
 
 
34
class LIBFM_QT_API BrowseHistoryItem {
 
35
public:
 
36
 
 
37
  BrowseHistoryItem():
 
38
    path_(NULL),
 
39
    scrollPos_(0) {
 
40
  }
 
41
 
 
42
  BrowseHistoryItem(FmPath* path, int scrollPos = 0):
 
43
    path_(fm_path_ref(path)),
 
44
    scrollPos_(scrollPos) {
 
45
  }
 
46
 
 
47
  BrowseHistoryItem(const BrowseHistoryItem& other):
 
48
    path_(other.path_ ? fm_path_ref(other.path_) : NULL),
 
49
    scrollPos_(other.scrollPos_) {
 
50
  }
 
51
 
 
52
  ~BrowseHistoryItem() {
 
53
    if(path_)
 
54
      fm_path_unref(path_);
 
55
  }
 
56
 
 
57
  BrowseHistoryItem& operator=(const BrowseHistoryItem& other) {
 
58
    if(path_)
 
59
      fm_path_unref(path_);
 
60
    path_ = other.path_ ? fm_path_ref(other.path_) : NULL;
 
61
    scrollPos_ = other.scrollPos_;
 
62
    return *this;
 
63
  }
 
64
 
 
65
  FmPath* path() const {
 
66
    return path_;
 
67
  }
 
68
 
 
69
  int scrollPos() const {
 
70
    return scrollPos_;
 
71
  }
 
72
 
 
73
  void setScrollPos(int pos) {
 
74
    scrollPos_ = pos;
 
75
  }
 
76
 
 
77
private:
 
78
  FmPath* path_;
 
79
  int scrollPos_;
 
80
  // TODO: we may need to store current selection as well. reserve room for furutre expansion.
 
81
  // void* reserved1;
 
82
  // void* reserved2;
 
83
};
 
84
 
 
85
class LIBFM_QT_API BrowseHistory : public QVector<BrowseHistoryItem> {
 
86
 
 
87
public:
 
88
  BrowseHistory();
 
89
  virtual ~BrowseHistory();
 
90
 
 
91
  int currentIndex() const {
 
92
    return currentIndex_;
 
93
  }
 
94
  void setCurrentIndex(int index);
 
95
 
 
96
  FmPath* currentPath() const {
 
97
    return at(currentIndex_).path();
 
98
  }
 
99
 
 
100
  int currentScrollPos() const {
 
101
    return at(currentIndex_).scrollPos();
 
102
  }
 
103
 
 
104
  BrowseHistoryItem& currentItem() {
 
105
    return operator[](currentIndex_);
 
106
  }
 
107
 
 
108
  void add(FmPath* path, int scrollPos = 0);
 
109
 
 
110
  bool canForward() const;
 
111
 
 
112
  bool canBackward() const;
 
113
 
 
114
  int backward();
 
115
 
 
116
  int forward();
 
117
 
 
118
  int maxCount() const {
 
119
    return maxCount_;
 
120
  }
 
121
 
 
122
  void setMaxCount(int maxCount);
 
123
 
 
124
private:
 
125
  int currentIndex_;
 
126
  int maxCount_;
 
127
};
 
128
 
 
129
}
 
130
 
 
131
#endif // FM_BROWSEHISTORY_H