File: global.cpp

package info (click to toggle)
basket 1.0.2-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 14,272 kB
  • ctags: 3,211
  • sloc: cpp: 28,424; sh: 9,518; perl: 2,730; makefile: 235
file content (100 lines) | stat: -rw-r--r-- 4,019 bytes parent folder | download
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
/***************************************************************************
 *   Copyright (C) 2003 by S´┐Żastien Laot                                 *
 *   slaout@linux62.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.                                   *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <kglobal.h>
#include <kstandarddirs.h>
#include <qstring.h>
#include <kaction.h>
#include <kapplication.h>
#include <kmainwindow.h>
#include <qdir.h>
#include <kdebug.h>
#include <kconfig.h>

#include "global.h"
#include "bnpview.h"
#include "settings.h"

/** Define initial values for global variables : */

QString            Global::s_customSavesFolder = "";
LikeBack          *Global::likeBack            = 0L;
DebugWindow       *Global::debugWindow         = 0L;
BackgroundManager *Global::backgroundManager   = 0L;
SystemTray        *Global::systemTray          = 0L;
BNPView           *Global::bnpView             = 0L;
KGlobalAccel      *Global::globalAccel         = 0L;
KConfig           *Global::basketConfig        = 0L;
AboutData          Global::basketAbout;

void Global::setCustomSavesFolder(const QString &folder)
{
	s_customSavesFolder = folder;
}

#include <iostream>
QString Global::savesFolder()
{
	static QString *folder = 0L; // Memorize the folder to do not have to re-compute it each time it's needed

	if (folder == 0L) {          // Initialize it if not yet done
		if (!s_customSavesFolder.isEmpty()) { // Passed by command line (for development & debug purpose)
			QDir dir;
			dir.mkdir(s_customSavesFolder);
			folder = new QString(s_customSavesFolder.endsWith("/") ? s_customSavesFolder : s_customSavesFolder + "/");
		} else if (!Settings::dataFolder().isEmpty()) { // Set by config option (in Basket -> Backup & Restore)
			QDir dir;
			dir.mkdir(s_customSavesFolder);
			folder = new QString(Settings::dataFolder().endsWith("/") ? Settings::dataFolder() : Settings::dataFolder() + "/");
		} else { // The default path (should be that for most computers)
			folder = new QString(KGlobal::dirs()->saveLocation("data", "basket/"));
		}
	}

	return *folder;
}

QString Global::basketsFolder()     { return savesFolder() + "baskets/";     }
QString Global::backgroundsFolder() { return savesFolder() + "backgrounds/"; }
QString Global::templatesFolder()   { return savesFolder() + "templates/";   }
QString Global::tempCutFolder()     { return savesFolder() + "temp-cut/";    }

QString Global::openNoteIcon() // FIXME: Now an edit icon
{
	return Global::bnpView->m_actEditNote->icon();
}

KMainWindow* Global::mainWindow()
{
	QWidget* res = kapp->mainWidget();

	if(res && res->inherits("KMainWindow"))
	{
		return static_cast<KMainWindow*>(res);
	}
	return 0;
}

KConfig* Global::config()
{
	if(!Global::basketConfig)
		Global::basketConfig = KSharedConfig::openConfig("basketrc");
	return Global::basketConfig;
}