summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/kopeteawaydialog.cpp
blob: 944e379fbd07cc3123ac6b470d3032876fbe9f1b (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
/*
    kopeteawaydialog.cpp - Kopete Away Dialog

    Copyright (c) 2002      by Hendrik vom Lehn       <hvl@linux-4-ever.de>
    Copyright (c) 2003      by Martijn Klingens       <klingens@kde.org>

    Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>

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

#include "kopeteawaydialog.h"

#include <kcombobox.h>
#include <kdebug.h>
#include <klineedit.h>
#include <klocale.h>
#include <kstringhandler.h>

#include "kopeteaway.h"
#include "kopeteawaydialogbase.h"

class KopeteAwayDialogPrivate
{
public:
	KopeteAwayDialog_Base *base;
};

KopeteAwayDialog::KopeteAwayDialog( TQWidget *tqparent, const char *name )
: KDialogBase( tqparent, name, true, i18n( "Global Away Message" ),
	KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, true )
{
	//kdDebug( 14010 ) << k_funcinfo << "Building KopeteAwayDialog..." << endl;

	d = new KopeteAwayDialogPrivate;

	d->base = new KopeteAwayDialog_Base( this );
	setMainWidget( d->base );

	TQObject::connect( d->base->cmbHistory, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( slotComboBoxSelection( int ) ) );

	awayInstance = Kopete::Away::getInstance();
	mExtendedAwayType = 0;
	init();

	//kdDebug( 14010 ) << k_funcinfo << "KopeteAwayDialog created." << endl;
}

KopeteAwayDialog::~KopeteAwayDialog()
{
	delete d;
}

void KopeteAwayDialog::slotComboBoxSelection( int index )
{
	// If they selected something out of the combo box
	// They probably want to use it
	d->base->txtOneShot->setText( awayInstance->getMessage(index) );
	d->base->txtOneShot->setCursorPosition( 0 );
}

void KopeteAwayDialog::show()
{
	// When this show is called, set the
	// mExtendedAwayType to the empty string
	mExtendedAwayType = 0;

	// Reinit the GUI
	init();

	//kdDebug( 14010 ) << k_funcinfo << "Showing Dialog with no extended away type" << endl;

	KDialogBase::show();
}

void KopeteAwayDialog::show( int awayType )
{
	mExtendedAwayType = awayType;

	// Reinit the GUI to set it up correctly
	init();

	kdDebug( 14010 ) << k_funcinfo << "Showing Dialog with extended away type " << awayType << endl;

	KDialogBase::show();
}

void KopeteAwayDialog::cancelAway( int /* awayType */ )
{
	/* Empty default implementation */
}

void KopeteAwayDialog::init()
{
	TQStringList awayMessages = awayInstance->getMessages();
	for( TQStringList::iterator it = awayMessages.begin(); it != awayMessages.end(); ++it )
	{
		*it = KStringHandler::rsqueeze( *it );
	}

	d->base->cmbHistory->clear();
	d->base->cmbHistory->insertStringList( awayMessages );
	d->base->txtOneShot->setText( awayMessages[0] );

	d->base->txtOneShot->setFocus();
	d->base->txtOneShot->setCursorPosition( 0 );
}

TQString KopeteAwayDialog::getSelectedAwayMessage()
{
	mLastUserAwayMessage = d->base->txtOneShot->text();
	return mLastUserAwayMessage;
}

void KopeteAwayDialog::slotOk()
{
	// Save the text the user typed
	mLastUserTypedMessage = d->base->txtOneShot->text();

	setAway( mExtendedAwayType );

	KDialogBase::slotOk();
}

void KopeteAwayDialog::slotCancel()
{
	// Call the virtual function with the type of away
	cancelAway( mExtendedAwayType );

	KDialogBase::slotCancel();
}

#include "kopeteawaydialog.moc"

// vim: set noet ts=4 sts=4 sw=4: