summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/kameraklient/dmessagebox.cpp
blob: f1a1262e00c0c6314b4cbda99dd482a24ec41215 (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
/* ============================================================
 * File  : dmessagebox.cpp
 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu>
 * Date  : 2003-02-22
 * Description :
 *
 * Copyright 2003 by Renchi Raju <renchi@pooh.tam.uiuc.edu>

 * Update : 09/23/2003 - Gilles Caulier <caulier.gilles@free.fr>
 *          Center the dialog box on the desktop.
 *          Improve i18n messages.

 * 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, 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.
 *
 * ============================================================ */

// TQt
#include <tqapplication.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpixmap.h>
#include <tqpushbutton.h>
#include <tqtextedit.h>
// KDE
#include <klocale.h>
#include <tdeapplication.h>
#include <kiconloader.h>
// Local
#include "dmessagebox.h"

namespace KIPIKameraKlientPlugin
{

DMessageBox* DMessageBox::s_instance = 0;

DMessageBox::DMessageBox() : TQWidget(0, 0, WShowModal | WStyle_DialogBorder| WDestructiveClose) {
    setCaption(i18n("Error"));
    s_instance = this;
    count_ = 0;
    TQGridLayout *grid = new TQGridLayout(this, 1, 1, 6, 11);
    // ----------------------------------------------------
    TQHBox *hbox = new TQHBox(this);
    hbox->setSpacing(5);
    TQPixmap pix = TDEApplication::kApplication()->iconLoader()->loadIcon("error",
                                                                       TDEIcon::NoGroup,
                                                                       TDEIcon::SizeMedium,
                                                                       TDEIcon::DefaultState,
								       0, true);
    TQLabel *pixLabel = new TQLabel(hbox);
    pixLabel->setPixmap(pix);
    pixLabel->setSizePolicy(TQSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Minimum));
    msgBox_ = new TQLabel(hbox);
    msgBox_->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Minimum));
    grid->addMultiCellWidget(hbox, 0, 0, 0, 2);
    // ---------------------------------------------------
    extraMsgBox_ = new TQTextEdit(this);
    extraMsgBox_->setReadOnly(true);
    grid->addMultiCellWidget(extraMsgBox_, 1, 1, 0, 2);
    extraMsgBox_->hide();
    // ---------------------------------------------------
    TQPushButton *okButton = new TQPushButton(i18n("&OK"), this);
    grid->addWidget(okButton, 2, 1);
    // ---------------------------------------------------
    grid->addItem(new TQSpacerItem(5, 10, TQSizePolicy::Expanding, TQSizePolicy::Minimum), 2, 0);
    grid->addItem(new TQSpacerItem(5, 10, TQSizePolicy::Expanding, TQSizePolicy::Minimum), 2, 2);
    // ---------------------------------------------------
    connect(okButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotOkClicked()));
    int W=500;
    int H=400;
    move(TQApplication::desktop()->width ()/2-(W/2), TQApplication::desktop()->height()/2-(H/2));
}

DMessageBox::~DMessageBox() {
    s_instance = 0;
}

void DMessageBox::appendMsg(const TQString& msg) {
    if (count_ == 0) {
        mainMsg_ = msg;
        msgBox_->setText(msg);
    } else {
        TQString text(i18n("More errors occurred and are shown below:"));
        msgBox_->setText(text);
        extraMsgBox_->append(msg);
        if (extraMsgBox_->isHidden()) {
            extraMsgBox_->show();
	}
    }
    count_++;
}

void DMessageBox::slotOkClicked() {
    close();
}

void DMessageBox::showMsg(const TQString& msg) {
    DMessageBox* msgBox = DMessageBox::s_instance;
    if (!msgBox) {
        msgBox = new DMessageBox;
    }
    msgBox->appendMsg(msg);
    if (msgBox->isHidden()) {
        msgBox->show();
    }
}

}  // NameSpace KIPIKameraKlientPlugin

#include "dmessagebox.moc"