1
/* -*- Mode: C++; coding: utf-8; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*-
2
*******************************************************************************
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
* Copyright create3000, Scheffelstraße 31a, Leipzig, Germany 2011.
8
* All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
10
* THIS IS UNPUBLISHED SOURCE CODE OF create3000.
12
* The copyright notice above does not evidence any actual of intended
13
* publication of such source code, and is an unpublished work by create3000.
14
* This material contains CONFIDENTIAL INFORMATION that is the property of
17
* No permission is granted to copy, distribute, or create derivative works from
18
* the contents of this software, in whole or in part, without the prior written
19
* permission of create3000.
21
* NON-MILITARY USE ONLY
23
* All create3000 software are effectively free software with a non-military use
24
* restriction. It is free. Well commented source is provided. You may reuse the
25
* source in any way you please with the exception anything that uses it must be
26
* marked to indicate is contains 'non-military use only' components.
28
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
30
* Copyright 1999, 2016 Holger Seelig <holger.seelig@yahoo.de>.
32
* This file is part of the Titania Project.
34
* Titania is free software: you can redistribute it and/or modify it under the
35
* terms of the GNU General Public License version 3 only, as published by the
36
* Free Software Foundation.
38
* Titania is distributed in the hope that it will be useful, but WITHOUT ANY
39
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
40
* A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
41
* details (a copy is included in the LICENSE file that accompanied this code).
43
* You should have received a copy of the GNU General Public License version 3
44
* along with Titania. If not, see <http://www.gnu.org/licenses/gpl.html> for a
45
* copy of the GPLv3 License.
47
* For Silvio, Joy and Adi.
49
******************************************************************************/
51
#include "BrowserHistory.h"
53
#include <Titania/X3D/Execution/X3DScene.h>
59
const io::character BrowserHistory::Grammar::tab ('\t');
60
const io::inverse_string BrowserHistory::Grammar::string ("\t");
62
BrowserHistory::BrowserHistory (X3D::X3DBrowser* const browser) :
69
browser -> initialized () .addInterest (&BrowserHistory::set_splashScreen, this);
73
BrowserHistory::set_splashScreen ()
75
browser -> initialized () .removeInterest (&BrowserHistory::set_splashScreen, this);
76
browser -> initialized () .addInterest (&BrowserHistory::set_initialized, this);
80
BrowserHistory::set_initialized ()
84
const X3D::X3DScenePtr scene (browser -> getExecutionContext ());
86
if (scene and scene -> getMetaData ("titania-history") == "FALSE")
89
catch (const X3D::X3DError &)
92
addURL (browser -> getExecutionContext () -> getTitle (), browser -> getWorldURL ());
98
BrowserHistory::connect (const X3D::SFBool & initialized)
100
initialized .removeInterest (&BrowserHistory::connect, this);
101
initialized .addInterest (&BrowserHistory::set_initialized, this);
107
BrowserHistory::assign (const int index, std::vector <Page> && list)
109
this -> index = index;
110
this -> list = std::move (list);
114
BrowserHistory::addURL (const std::string & title, const basic::uri & URL)
116
if (index >= 0 and list [index] .second == URL)
119
list .resize (index + 1);
121
list .emplace_back (title, URL);
127
BrowserHistory::setIndex (const int value)
129
if (value < 0 or value >= (int) list .size ())
134
browser -> initialized () .removeInterest (&BrowserHistory::set_initialized, this);
135
browser -> initialized () .addInterest (&BrowserHistory::connect, this);
137
browser -> loadURL ({ list [index] .second .str () }, { });
141
BrowserHistory::hasPreviousPage () const
147
BrowserHistory::hasNextPage () const
149
return index + 1 < (int) list .size ();
153
BrowserHistory::previousPage ()
155
setIndex (index - 1);
159
BrowserHistory::nextPage ()
161
setIndex (index + 1);
165
BrowserHistory::fromString (const std::string & string)
167
std::istringstream isstream (string);
169
isstream .imbue (std::locale::classic ());
171
fromStream (isstream);
175
BrowserHistory::fromStream (std::istream & istream)
179
std::vector <Page> list;
181
if (not (istream >> index))
189
assign (index, std::move (list));
193
if (not Grammar::tab (istream))
198
std::pair <std::string, std::string> page;
200
if (not Grammar::string (istream, page .first))
203
Grammar::string (istream, page .second);
205
list .emplace_back (std::move (page));
208
if (index < (int) list .size ())
209
assign (index, std::move (list));
213
BrowserHistory::toString () const
215
std::ostringstream osstream;
217
osstream .imbue (std::locale::classic ());
221
return osstream .str ();
225
BrowserHistory::toStream (std::ostream & ostream) const
229
for (const auto & pair : list)
230
ostream << Grammar::tab () << pair .first << Grammar::tab () << pair .second;