summaryrefslogtreecommitdiffstats
path: root/kpilot/pilotComponent.cpp
blob: 0172a44ea099f39dffe77c990801cd7ade0ae140 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* KPilot
**
** Copyright (C) 1998-2001 by Dan Pilone
** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
**
** This file defines a base class for components -- internal conduits --
** in KPilot. This includes a number of general utility functions.
*/

/*
** 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 in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/

/*
** Bug reports and questions can be sent to kde-pim@kde.org
*/


#include "options.h"

#include <time.h>

#include <pi-appinfo.h>

#include <tqwidget.h>
#include <tqcombobox.h>

#include <kdebug.h>

#include "kpilotConfig.h"
#include "pilotRecord.h"
#include "pilot.h"

#include "pilotComponent.moc"

PilotComponent::PilotComponent(TQWidget * parent,
	const char *id,
	const TQString & path) :
	TQWidget(parent, id),
	fDBPath(path),
	shown(false)
{
	FUNCTIONSETUP;

	if (parent)
	{
		resize(parent->geometry().width(),
			parent->geometry().height());
	}

}



int PilotComponent::findSelectedCategory(TQComboBox * fCatList,
	struct CategoryAppInfo *info, bool AllIsUnfiled)
{
	FUNCTIONSETUP;

	// Semantics of currentCatID are:
	//
	// >=0          is a specific category based on the text ->
	//              category number mapping defined by the Pilot,
	// ==-1         means "All" category selected when
	//              AllIsUnfiled is true.
	// == 0         == Unfiled means "All" category selected when
	//              AllIsUnfiled is false.
	//
	//
	int currentCatID = 0;

	// If a category is deleted after others have been added, none of the
	// category numbers are changed.  So we need to find the category number
	// for this category (this category is represented by the selected
	// *text*).
	//
	//
	// The top entry in the list is "All", so if the top item is
	// selected we can indicate that we are using the "All" category.
	//
	//
	if (fCatList->currentItem() == 0)
	{
		currentCatID = (-1);
#ifdef DEBUG
		DEBUGKPILOT << fname << ": Category 'All' selected.\n";
#endif
	}
	else
	{
		TQString selectedCategory =
			fCatList->text(fCatList->currentItem());
		currentCatID = Pilot::findCategory(info, selectedCategory, AllIsUnfiled);
	}

	if ((currentCatID == -1) && AllIsUnfiled)
		currentCatID = 0;
	return currentCatID;
}


void PilotComponent::populateCategories(TQComboBox * c,
	struct CategoryAppInfo *info)
{
	FUNCTIONSETUP;

#ifdef DEBUG
	DEBUGKPILOT << fname
		<< ": Combo box @"
		<< (long) c << " and info @" << (long) info << endl;
#endif

	c->clear();

	if (!info)
		goto CategoryAll;

	// Fill up the categories list box with
	// the categories defined by the user.
	// These presumably are in the language
	// the user uses, so no translation is necessary.
	//
	//
	for (unsigned int i = 0; i < Pilot::CATEGORY_COUNT; i++)
	{
		if (info->name[i][0])
		{
#ifdef DEBUG
			DEBUGKPILOT << fname
				<< ": Adding category: "
				<< info->name[i]
				<< " with ID: " << (int) info->ID[i] << endl;
#endif

			c->insertItem(Pilot::fromPilot(info->name[i]));
		}
	}

CategoryAll:
	c->insertItem(i18n("All"), 0);
}


void PilotComponent::slotShowComponent()
{
	FUNCTIONSETUP;

#ifdef DEBUG
	DEBUGKPILOT << fname << ": Showing component @" << (long) this << endl;
#endif

	emit showComponent(this);
}

/* virtual */ bool PilotComponent::preHotSync(TQString &)
{
	FUNCTIONSETUP;

	return true;
}

void PilotComponent::markDBDirty(const TQString db)
{
	FUNCTIONSETUP;
	KPilotConfig::addDirtyDatabase(db);
	KPilotConfig::sync();
}

void PilotComponent::showKPilotComponent( bool toShow )
{
	if ( toShow != shown )
	{
		shown = toShow;
		if (shown) showComponent();
		else hideComponent();
	}
}