summaryrefslogtreecommitdiffstats
path: root/noatun-plugins/lyrics/historymanager.cpp
blob: 629466dd55b01ce4dd113437dcede6e4d4ea468e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "historymanager.h"

/** HISTORY MANAGER ***
*** TODO: Add more complex support (like in Konqueror)
          Maybe use Konqueror's History Manager */

HistoryManager::HistoryManager(TQObject *parent) : TQObject(parent) {
}

HistoryManager::~HistoryManager() {
}

void HistoryManager::addURL(const KURL &url) {
  /* push current URL to the back */
  if (!currentURL.isEmpty()) {
    if (back_stack.count() == 0)
      emit uiChanged( Back, true );
    back_stack.push(currentURL);
  }
  /* Make a copy of the new URL */
  currentURL = url;
  /* Clear the forward stack */
  if (forward_stack.count() > 0)
    emit uiChanged( Forward, false );
  forward_stack.clear();
}

KURL HistoryManager::back() {
  if (back_stack.count() <= 0)
    return KURL();
  /* The currentURL is now pushed in the forward_stack */
  if (forward_stack.count() == 0)
    emit uiChanged( Forward, true );
  forward_stack.push(currentURL);
  /* The last URL is the back stack is now popped as the current one */
  if (back_stack.count() == 1)
    emit uiChanged( Back, false );
  currentURL = back_stack.pop();
  return currentURL;
}

KURL HistoryManager::forward() {
  if (forward_stack.count() <= 0)
    return KURL();
  /* Push the currentURL into the back_stack */
  if (back_stack.count() == 0)
    emit uiChanged( Back, true );
  back_stack.push(currentURL);
  /* Pop from the forward_stack into the currentURL */
  if (forward_stack.count() == 1)
    emit uiChanged( Forward, false );
  currentURL = forward_stack.pop();
  return currentURL;
}

#include "historymanager.moc"