summaryrefslogtreecommitdiffstats
path: root/src/kile/docpart.cpp
blob: 331c071660ca092862bf668294a0041082759afa (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/***************************************************************************
    begin                : Sun Jul 29 2001
    copyright            : (C) 2001 - 2003 by Brachet Pascal, (C) 2004 by Jeroen Wijnhout
    email                : Jeroen.Wijnhout@kdemail.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "docpart.h"

#include <tdeconfig.h>
#include <kstdaction.h>
#include <kglobal.h>
#include "kiledebug.h"
#include <kstandarddirs.h>
#include <kmimemagic.h>
#include <kmimetype.h>
#include <ktrader.h>
#include <krun.h>
#include <tdehtml_part.h>
#include <tdehtml_settings.h>

DocumentationViewer::DocumentationViewer(TQWidget *parent, const char *name ) : TDEHTMLPart(parent,name, 0, 0, BrowserViewGUI)
{
	m_hpos = 0;
	TDEConfig konqConfig("konquerorrc");
	konqConfig.setGroup("HTML Settings");
	//const TDEHTMLSettings * set = settings();
	//( const_cast<TDEHTMLSettings *>(set) )->init( &konqConfig, false );
	TQString rc = TDEGlobal::dirs()->findResource("appdata", "docpartui.rc");
	setXMLFile(rc);
	(void) KStdAction::back(this, TQT_SLOT(back()), actionCollection(),"Back" );
	(void) KStdAction::forward(this, TQT_SLOT(forward()), actionCollection(),"Forward" );
	(void) KStdAction::home(this, TQT_SLOT(home()), actionCollection(),"Home" );
}

DocumentationViewer::~DocumentationViewer() {}

void DocumentationViewer::urlSelected(const TQString &url, int button, int state,const TQString & target, KParts::URLArgs args)
{
	KURL cURL = completeURL(url);
	TQString mime = KMimeType::findByURL(cURL).data()->name();

	//load this URL in the embedded viewer if TDEHTML can handle it, or when mimetype detection failed
	KService::Ptr service = KService::serviceByDesktopName("tdehtml");
	if ( ( mime == KMimeType::defaultMimeType() ) || (service && service->hasServiceType(mime)) )
	{
		TDEHTMLPart::urlSelected(url, button, state, target, args);
		openURL(cURL) ;
		addToHistory(cURL.url());
	}
	//TDEHTML can't handle it, look for an appropriate application
	else
	{
		TDETrader::OfferList offers = TDETrader::self()->query(mime, "Type == 'Application'");
		KService::Ptr ptr = offers.first();
		KURL::List lst;
		lst.append(cURL);
		if (ptr) KRun::run(*ptr, lst);
	}
}

void DocumentationViewer::home()
{
	if ( !m_history.isEmpty() ) openURL( KURL(m_history.first()) );
}

void DocumentationViewer::forward()
{
	if ( forwardEnable() ) 
	{
		++m_hpos;
		openURL( KURL( m_history[m_hpos]) );
		emit updateStatus( backEnable() , forwardEnable() );
	}
}


void DocumentationViewer::back()
{
	if ( backEnable() ) {
		--m_hpos;
		openURL( KURL(m_history[m_hpos]) );
		emit updateStatus( backEnable() , forwardEnable() );
	}
}


void DocumentationViewer::addToHistory( const TQString & url )
{
	if ( m_history.count() > 0 )
	{
		while ( m_hpos < m_history.count()-1  )
				m_history.pop_back();
	}
	
	if ( !m_history.isEmpty() ) ++m_hpos;
	
	m_history.append(url);
	
	m_hpos = m_history.count()-1;
	emit updateStatus( backEnable() , forwardEnable() );
}


bool DocumentationViewer::backEnable()
{
	return m_hpos > 0;
}


bool DocumentationViewer::forwardEnable()
{
	return m_hpos < m_history.count()-1;
}

#include "docpart.moc"