summaryrefslogtreecommitdiffstats
path: root/parts/documentation/find_documentation_options.cpp
blob: df04ca81abd5b9d14f3daef57f4b575402cfcb90 (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
191
192
/***************************************************************************
 *   Copyright (C) 2004 by Tobias Glaesser                                 *
 *   [email protected]                                                       *
 *                                                                         *
 *   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 "find_documentation_options.h"

#include <tqheader.h>
#include <tqcheckbox.h>

#include <klistview.h>
#include <klocale.h>

#include <kconfig.h>
#include <kapplication.h>

FindDocumentationOptions::FindDocumentationOptions(TQWidget* parent, const char* name, bool modal)
    :FindDocumentationOptionsBase(parent,name, modal),
    m_man_item(0), m_info_item(0), m_index_item(0), m_google_item(0), m_contents_item(0)
{        
    readOptions();
    
    source_list->header()->hide();
    source_list->setSorting(-1);
}

FindDocumentationOptions::~FindDocumentationOptions()
{
}

/*$SPECIALIZATION$*/
bool FindDocumentationOptions::isContents( TQCheckListItem * item )
{
    if ( item == m_contents_item && m_contents_item->isOn()  )
        return true;
    else 
        return false;
}

bool FindDocumentationOptions::isGoogle( TQCheckListItem * item )
{
    if ( item == m_google_item && m_google_item->isOn()  )
        return true;
    else 
        return false;
}

bool FindDocumentationOptions::isIndex( TQCheckListItem * item )
{
    if ( item == m_index_item  && m_index_item->isOn() )
        return true;
    else 
        return false;
}

bool FindDocumentationOptions::isInfo( TQCheckListItem * item )
{
    if ( item == m_info_item  && m_info_item->isOn() )
        return true;
    else 
        return false;
}

bool FindDocumentationOptions::isMan( TQCheckListItem * item )
{
    if ( item == m_man_item && m_man_item->isOn() )
        return true;
    else 
        return false;
}

void FindDocumentationOptions::sourceMoveDown()
{
    if (!source_list->currentItem())
        return;
    if (source_list->currentItem()->nextSibling() == 0)
        return;

    source_list->currentItem()->moveItem(source_list->currentItem()->nextSibling()); 
}

void FindDocumentationOptions::sourceMoveUp()
{
    if (!source_list->currentItem())
        return;
    if (source_list->currentItem() == source_list->firstChild()) 
        return;
    
    TQListViewItem *item = source_list->firstChild();
    while (item->nextSibling() != source_list->currentItem())
        item = item->nextSibling();
    item->moveItem( source_list->currentItem()); 
}

void FindDocumentationOptions::writeOptions()
{
    config = kapp->config();
    config->setGroup("DocumentationFinder");
    
    config->writeEntry("goto_first_match", goto_first_match->isChecked());
    
    TQListViewItemIterator it( source_list );
    int i = 0;
    while ( it.current() ) 
    {
        if ( it.current() == m_man_item )
        {
            config->writeEntry("Manpage",i);
            config->writeEntry("ManpageEnabled",m_man_item->isOn());
        }
        else if ( it.current() == m_info_item )
        {
            config->writeEntry("Info",i);
            config->writeEntry("InfoEnabled",m_info_item->isOn());
        }
        else if ( it.current() == m_index_item )
        {
            config->writeEntry("Index",i);
            config->writeEntry("IndexEnabled",m_index_item->isOn());
        }
        else if ( it.current() == m_google_item )
        {
            config->writeEntry("Google",i);
            config->writeEntry("GoogleEnabled",m_google_item->isOn());
        }
        else if ( it.current() == m_contents_item )
        {
            config->writeEntry("Contents",i);
            config->writeEntry("ContentsEnabled",m_contents_item->isOn());
        }
        ++it;
        ++i;
    }  
    
    config->sync();
}

void FindDocumentationOptions::readOptions()
{
    config = kapp->config();
    config->setGroup("DocumentationFinder");
    
    source_list->clear();
    
    for(int i = 4; i > -1; --i  )
    {
        if( config->readPropertyEntry( "Manpage" , 0 ) == i)
        {
            m_man_item  = new TQCheckListItem( source_list, i18n("Manual"), TQCheckListItem::CheckBox );
            m_man_item->setOn(config->readBoolEntry( "ManpageEnabled" , true));
        }
        if( config->readPropertyEntry( "Info" , 1 ) == i)
        {
            m_info_item = new TQCheckListItem( source_list, i18n("Info"), TQCheckListItem::CheckBox );
            m_info_item->setOn(config->readBoolEntry( "InfoEnabled" , true));
        }
        if( config->readPropertyEntry( "Index" , 2 ) == i)
        {
            m_index_item = new TQCheckListItem( source_list, i18n("Index"), TQCheckListItem::CheckBox );
            m_index_item->setOn(config->readBoolEntry( "IndexEnabled" , true));
        }
        if( config->readPropertyEntry( "Google" , 3 ) == i)
        {
            m_google_item = new TQCheckListItem( source_list, i18n("Google"), TQCheckListItem::CheckBox );
            m_google_item->setOn(config->readBoolEntry( "GoogleEnabled" , false)); 
        }
        if( config->readPropertyEntry( "Contents" , 4 ) == i)
        {
            m_contents_item = new TQCheckListItem( source_list, i18n("Contents"), TQCheckListItem::CheckBox );
            m_contents_item->setOn(config->readBoolEntry( "ContentsEnabled" , false)); 
        }      
    }
    
    goto_first_match->setChecked(config->readBoolEntry( "goto_first_match" , false));
}

#include "find_documentation_options.moc"