summaryrefslogtreecommitdiffstats
path: root/keduca/keduca/keduca.cpp
blob: 7dfe7c8e087816b0cb22ac51de409d50f295ffc4 (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
125
126
127
128
129
130
/***************************************************************************
                          keduca.cpp  -  description
                             -------------------
    begin                : mié may 23 20:36:15 CEST 2001
    copyright            : (C) 2001 by Javier Campos
    email                : javi@asyris.org
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "keduca.h"
#include "keduca.moc"
#include "keduca_part.h"
#include "../libkeduca/kgallerydialog.h"

#include <kapplication.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kfiledialog.h>
#include <kdebug.h>

#include <kparts/componentfactory.h>

#include <tqlabel.h>

Keduca::Keduca( TQWidget* parent, const char *name, WFlags f )
	: KParts::MainWindow( parent, name, f ), _part( 0 )
{
	setXMLFile( "keducaui.rc" );
	
	_part = KParts::ComponentFactory::createPartInstanceFromLibrary< KParts::ReadOnlyPart >
	        ( "libkeducapart", this, name, this, "KEducaPart" );
	
	if ( _part )
	{
		setCentralWidget( _part->widget() );
		
		setupActions();
		
		configRead();
		
		createGUI( _part );
	}
	else
	{
		kdFatal() << "The library \"libkeducapart\" could not be found. Aborting." << endl;
	}
	if (!initialGeometrySet())
		resize( TQSize(550, 450).expandedTo(tqminimumSizeHint()));
}

Keduca::~Keduca()
{
}


void Keduca::setupActions()
{
	KStdAction::open( this, TQT_SLOT( slotFileOpen() ), actionCollection() );
	(void)new KAction(  i18n( "Open &Gallery..." ), 0, 0, this, TQT_SLOT( slotGallery() ),
actionCollection(), "open_gallery" );
	_recentFiles = KStdAction::openRecent(this, TQT_SLOT ( slotFileOpenURL(const KURL &) ),
actionCollection());
	KStdAction::quit(kapp, TQT_SLOT( quit() ), actionCollection());
}

void Keduca::slotFileOpen()
{
	KURL url = KFileDialog::getOpenURL( TQString::null, "application/x-edu", this,  i18n("Open Educa File") );
	if( !url.isEmpty() )
		slotFileOpenURL( url );
}

void Keduca::slotFileOpenURL( const KURL &url )
{
	if( !_part->openURL(url) ) return; 
	_recentFiles->addURL( url );
}

/*void Keduca::slotFileClose()
{
	init();
}*/

bool Keduca::queryClose()
{
	configWrite();
	return( TRUE );
}

void Keduca::configRead()
{
	KConfig *config = KGlobal::config();
	config->setGroup( "keduca" );
	applyMainWindowSettings( config, "keduca" );
	_recentFiles->loadEntries(config);
}

void Keduca::configWrite()
{
	KConfig *config = KGlobal::config();
	
	config->setGroup( "keduca" );
	saveMainWindowSettings( config, "keduca" );
	_recentFiles->saveEntries(config);
	config->sync();
}

void Keduca::slotGallery()
{
  	initGallery();
}

void Keduca::initGallery(const KURL &urlFile)
{
	KGalleryDialog galleries;
	
	if( !urlFile.url().isEmpty() )
	galleries.putURL( urlFile );
	
	if( galleries.exec() == TQDialog::Accepted )
	slotFileOpenURL( galleries.getURL() );
}