summaryrefslogtreecommitdiffstats
path: root/kate/katesort/sortdialog.cpp
blob: 53c5b22afa168a2dbe6f4dd627aef7e2c0c9c84c (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
/***************************************************************************
 *   Copyright (C) 2007 by Marian Kyral                                    *
 *   mkyral@email.cz                                                       *
 *                                                                         *
 *   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 "sortdialog.h"
#include "tdeconfig.h"
#include <tqwhatsthis.h>

SortDialog::SortDialog ( TQWidget* parent, const char* name, bool modal, WFlags fl )
		: sortdialoglayout ( parent,name, modal,fl )
{
  // set labels
  TQWhatsThis::add(m_radioButtonAsc,i18n(
    "Sort in ascending order "
    "(from A to Z or 0 to 9)."));
  TQWhatsThis::add(m_radioButtonDesc,i18n(
    "Sort in descending order "
    "(from Z to A or 9 to 0)."));
  TQWhatsThis::add(m_checkBoxCase,i18n(
    "Check this for case sensitive sort."));
  TQWhatsThis::add(m_checkBoxUnique,i18n(
    "Check this to remove all duplicated records."));
  TQWhatsThis::add(m_checkBoxByCol,i18n(
    "Check this for sorting by specific column.\n\n"
    "If a part of one line is selected, "
    "this checkbox is automatically selected. "
    "Start and end fields are filled according to selection."));
  TQWhatsThis::add(m_lineEditStartCol,i18n(
    "Start column of the sorting area."));
  TQWhatsThis::add(m_lineEditEndCol,i18n(
    "End column of the sorting area."));
  TQWhatsThis::add(m_radioButtonAlphaSort,i18n(
    "Alphabetical sorting (A-Z)."));
  TQWhatsThis::add(m_radioButtonNumSort,i18n(
    "Numeric sorting (0-9)"));

  config_load();
}

SortDialog::~SortDialog()
{}

/*$SPECIALIZATION$*/
void SortDialog::reject()
{
	TQDialog::reject();
}

void SortDialog::accept()
{
	if (m_checkBoxByCol->isChecked())
  {
    if (m_lineEditStartCol->text().isEmpty() ||
        m_lineEditStartCol->text().toInt() == 0 ||
        m_lineEditEndCol->text().isEmpty() ||
        m_lineEditEndCol->text().toInt() == 0)
    {
      TQMessageBox::warning(this,i18n("Error"),
                                i18n("Fields:\n\"Starting at\" and \"Ending at\"\nhave to contains numbers."),
                                i18n("OK"));
      return;
    }
  }
  config_save();
  TQDialog::accept();
}

int SortDialog::exec()
{
  return TQDialog::exec();
}

void SortDialog::toggledCol()
{
   if (m_lineEditStartCol->isEnabled())
   {
     m_lineEditStartCol->setEnabled(false);
     m_lineEditEndCol->setEnabled(false);
   }
   else
   {
     m_lineEditStartCol->setEnabled(true);
     m_lineEditEndCol->setEnabled(true);
   }
}

void SortDialog::toggledType()
{
  if (m_radioButtonAlphaSort->isChecked())
    m_checkBoxCase->setEnabled(true);
  else
    m_checkBoxCase->setEnabled(false);
}

void SortDialog::config_load ()
{
//   tqDebug("config_load()");
  TDEConfig *config = new TDEConfig("katesortpluginrc");
  m_radioButtonAsc->setChecked(config->readBoolEntry("Asc",true));
  m_radioButtonDesc->setChecked(config->readBoolEntry("Desc",false));
  m_radioButtonAlphaSort->setChecked(config->readBoolEntry("Alpha",true));
  m_radioButtonNumSort->setChecked(config->readBoolEntry("Num",false));
  m_checkBoxCase->setChecked(config->readBoolEntry("Case",false));
  m_checkBoxUnique->setChecked(config->readBoolEntry("Unique",false));
  m_checkBoxByCol->setChecked(config->readBoolEntry("By col",false));
  m_lineEditStartCol->setText(config->readEntry("Start col"));
  m_lineEditEndCol->setText(config->readEntry("End col"));
}

void SortDialog::config_save ()
{
//   tqDebug("config_save()");
  TDEConfig *config = new TDEConfig("katesortpluginrc");
  config->writeEntry("Asc",m_radioButtonAsc->isOn());
  config->writeEntry("Desc", m_radioButtonDesc->isOn());
  config->writeEntry("Alpha",m_radioButtonAlphaSort->isOn());
  config->writeEntry("Num", m_radioButtonNumSort->isOn());
  config->writeEntry("Case", m_checkBoxCase->isOn());
  config->writeEntry("Unique", m_checkBoxUnique->isOn());
  config->writeEntry("By col", m_checkBoxByCol->isOn());
  config->writeEntry("Start col", m_lineEditStartCol->text());
  config->writeEntry("End col", m_lineEditEndCol->text());
  config->sync();
}

#include "sortdialog.moc"