summaryrefslogtreecommitdiffstats
path: root/src/app/main.cpp
blob: 27ec8c305b34812eb80ecbde052f30c9e2a5ee1f (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// vim: set tabstop=4 shiftwidth=4 noexpandtab
/*
Gwenview - A simple image viewer for TDE
Copyright 2000-2006 Aurelien Gateau

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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/
#include <tqdir.h>

#include <tdeaboutdata.h>
#include <tdeapplication.h>
#include <tdecmdlineargs.h>
#include <kdebug.h>
#include <tdelocale.h>

#include "gvcore/cache.h"
#include "gvcore/fileviewcontroller.h"
#include <../gvcore/fileviewconfig.h>
#include <../gvcore/miscconfig.h>
#include "mainwindow.h"
namespace Gwenview {

static TDECmdLineOptions options[] = {
	{ "f", I18N_NOOP("Start in fullscreen mode"), 0 },
	{ "filter-type <all,images,videos>", I18N_NOOP("Filter by file type"), 0 },
	{ "filter-name <pattern>", I18N_NOOP("Filter by file pattern (*.jpg, 01*...)"), 0 },
	{ "filter-from <date>", I18N_NOOP("Only show files newer or equal to <date>"), 0 },
	{ "filter-to <date>", I18N_NOOP("Only show files older or equal to <date>"), 0 },
	{ "+[file or folder]", I18N_NOOP("A starting file or folder"), 0 },
	TDECmdLineLastOption
};

static const char version[] = "1.4.2";


void applyFilterArgs(TDECmdLineArgs* args, FileViewController* controller) {
	TQString filterType = args->getOption("filter-type");
	TQString filterName = args->getOption("filter-name");
	TQString filterFrom = args->getOption("filter-from");
	TQString filterTo = args->getOption("filter-to");
	// Do nothing if there is no filter
	if (filterType.isEmpty() && filterName.isEmpty() 
		&& filterFrom.isEmpty() && filterTo.isEmpty())
	{
		return;
	}

	TQStringList typeList;
	typeList << "all" << "images" << "videos";
	int mode = typeList.findIndex(filterType);
	if (mode == -1) {
		// Default to "all"
		controller->setFilterMode(0);
	} else {
		controller->setFilterMode(mode);
	}

	controller->setShowFilterBar(
		!filterName.isEmpty()
		|| !filterFrom.isEmpty()
		|| !filterTo.isEmpty() );

	controller->setFilterName(filterName);

	bool ok = false;
	TQDate date;
	if (!filterFrom.isEmpty()) {
		date = TDEGlobal::locale()->readDate(filterFrom, &ok);
		if (!ok) {
			kdWarning() << "Invalid value for filter-from option\n";
		}
	}
	controller->setFilterFromDate(date);

	date=TQDate();
	if (!filterTo.isEmpty()) {
		date = TDEGlobal::locale()->readDate(filterTo, &ok);
		if (!ok) {
			kdWarning() << "Invalid value for filter-to option\n";
		}
	}
	controller->setFilterToDate(date);

	controller->applyFilter();
}


#ifndef __KDE_HAVE_GCC_VISIBILITY
#undef KDE_EXPORT
#define KDE_EXPORT
#endif

extern "C"
KDE_EXPORT int kdemain (int argc, char *argv[]) {
	TDEAboutData aboutData("gwenview", I18N_NOOP("Gwenview"),
		version, I18N_NOOP("An image viewer for TDE"), TDEAboutData::License_GPL,
		"Copyright 2000-2006, The Gwenview developers",0,"http://gwenview.sourceforge.net");
	aboutData.addAuthor("Aurélien Gâteau", I18N_NOOP("Main developer"), "aurelien.gateau@free.fr");
	aboutData.addAuthor("Luboš Luňák", I18N_NOOP("Developer"), "l.lunak@suse.cz");

	aboutData.addCredit("Frank Becker", I18N_NOOP("Fast JPEG thumbnail generation (v0.13.0)"), "ff@telus.net");
	aboutData.addCredit("Tudor Calin", I18N_NOOP("Address bar (v0.16.0)\nHistory support (v1.0.0)"), "tudor_calin@mymail.ro");
	aboutData.addCredit("Avinash Chopde", I18N_NOOP("File operation patch (v0.9.2)"), "avinash@acm.org");
	aboutData.addCredit("Marco Gazzetta", I18N_NOOP("Fixed crash when trying to generate a thumbnail for a broken JPEG file (v0.16.0)"), "mililani@pobox.com");
	aboutData.addCredit("GeniusR13", I18N_NOOP("Fixed compilation on KDE 3.0 (v0.16.1)"), "geniusr13@gmx.net");
	aboutData.addCredit("Ian Koenig", I18N_NOOP("First RPM spec file"), "iguy@ionsphere.org");
	aboutData.addCredit("Meni Livne", I18N_NOOP("Toolbar layout patch for RTL languages (v0.16.0)"), "livne@kde.org");
	aboutData.addCredit("Angelo Naselli", I18N_NOOP("Printing support (v1.0.0)"), "anaselli@linux.it");
	aboutData.addCredit("Jos van den Oever", I18N_NOOP("File info view (v1.0.0)\nPatch to toggle auto-zoom on click (v1.0.0)"), "jos@vandenoever.info");
	aboutData.addCredit("Jeroen Peters", I18N_NOOP("Configurable mouse wheel behavior (v1.1.1)"), "jpeters@coldmail.nl");
	aboutData.addCredit("Andreas Pfaller", I18N_NOOP("Option to prevent Gwenview from automatically loading the first image of a folder (v0.15.0)"), "apfaller@yahoo.com.au");
	aboutData.addCredit("Renchi Raju", I18N_NOOP("Fixed thumbnail generation to share the thumbnail folder of Konqueror v3 (v0.15.0)"), "renchi@green.tam.uiuc.edu");
	aboutData.addCredit("Michael Spanier", I18N_NOOP("Patch for mouse navigation (v0.7.0)"), "mail@michael-spanier.de");
	aboutData.addCredit("Christian A Strømmen", I18N_NOOP("Integration in Konqueror folder context menu"), "number1@realityx.net");

	TDECmdLineArgs::init( argc, argv, &aboutData );
	TDECmdLineArgs::addCmdLineOptions( options );

	TDEApplication tdeapplication;

	if (tdeapplication.isRestored()) {
		RESTORE(MainWindow)
	} else {
		TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();

		MainWindow *mainWindow = new MainWindow;
		applyFilterArgs(args, mainWindow->fileViewController());

		bool fullscreen=args->isSet("f");
		if (fullscreen) mainWindow->setFullScreen(true);

		KURL url;
		if (args->count()>0) {
			url=args->url(0);
		} else {
			if (MiscConfig::rememberURL() && MiscConfig::history().count() > 0) {
				url = KURL(MiscConfig::history()[0]);
			} else {
				url.setPath( TQDir::currentDirPath() );
			}
		}
		mainWindow->openURL(url);
		
		mainWindow->show();
	}

	return tdeapplication.exec();
}

} // namespace