summaryrefslogtreecommitdiffstats
path: root/tderesources/scalix/scalixadmin/outofofficepage.cpp
blob: 557772d896ea70e65f6bbc0daea92a39ae12799e (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
/*
 *   This file is part of ScalixAdmin.
 *
 *   Copyright (C) 2007 Trolltech ASA. All rights reserved.
 *
 *   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 <tqbuttongroup.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpushbutton.h>
#include <tqradiobutton.h>
#include <tqtextedit.h>

#include <tdelocale.h>
#include <tdemessagebox.h>

#include "jobs.h"
#include "settings.h"

#include "outofofficepage.h"

OutOfOfficePage::OutOfOfficePage( TQWidget *parent )
  : TQWidget( parent )
{
  TQGridLayout *layout = new TQGridLayout( this, 4, 2, 11, 6 );

  TQButtonGroup *group = new TQButtonGroup( 1, TQt::Vertical, this );

  mDisabled = new TQRadioButton( i18n( "I am in the office" ), group );
  mDisabled->setChecked( true );
  mEnabled = new TQRadioButton( i18n( "I am out of the office" ), group );

  mLabel = new TQLabel( i18n( "Auto-reply once to each sender with the following text:" ), this );
  mMessage = new TQTextEdit( this );
  mSaveButton = new TQPushButton( i18n( "Save" ), this );

  layout->addMultiCellWidget( group, 0, 0, 0, 1 );
  layout->addMultiCellWidget( mLabel, 1, 1, 0, 1 );
  layout->addMultiCellWidget( mMessage, 2, 2, 0, 1 );
  layout->addWidget( mSaveButton, 3, 1 );

  statusChanged();

  connect( mEnabled, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( statusChanged() ) );
  connect( mEnabled, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( changed() ) );
  connect( mSaveButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( store() ) );
  connect( mMessage, TQT_SIGNAL( textChanged() ), this, TQT_SLOT( changed() ) );

  load();
}

OutOfOfficePage::~OutOfOfficePage()
{
}

void OutOfOfficePage::load()
{
  Scalix::GetOutOfOfficeJob *job = Scalix::getOutOfOffice( Settings::self()->globalSlave(),
                                                           Settings::self()->accountUrl() );
  connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( loaded( TDEIO::Job* ) ) );
}

void OutOfOfficePage::loaded( TDEIO::Job* job )
{
  if ( job->error() ) {
    KMessageBox::error( this, job->errorString() );
    return;
  }

  Scalix::GetOutOfOfficeJob *outOfOfficeJob = static_cast<Scalix::GetOutOfOfficeJob*>( job );

  mEnabled->setChecked( outOfOfficeJob->enabled() );
  mMessage->setText( outOfOfficeJob->message() );

  statusChanged();

  mSaveButton->setEnabled( false );
}

void OutOfOfficePage::store()
{
  Scalix::SetOutOfOfficeJob *job = Scalix::setOutOfOffice( Settings::self()->globalSlave(),
                                                           Settings::self()->accountUrl(),
                                                           mEnabled->isChecked(),
                                                           mMessage->text() );

  connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), TQT_SLOT( stored( TDEIO::Job* ) ) );

  mSaveButton->setEnabled( false );
}

void OutOfOfficePage::stored( TDEIO::Job* job )
{
  if ( job->error() )
    KMessageBox::error( this, job->errorString() );
}

void OutOfOfficePage::statusChanged()
{
  bool state = mEnabled->isChecked();

  mLabel->setEnabled( state );
  mMessage->setEnabled( state );
}

void OutOfOfficePage::changed()
{
  mSaveButton->setEnabled( true );
}

#include "outofofficepage.moc"