~ubuntu-branches/ubuntu/lucid/konversation/lucid-updates

« back to all changes in this revision

Viewing changes to src/preferences/autoreplace_preferences.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Modestas Vainius
  • Date: 2009-05-15 11:24:24 UTC
  • mfrom: (1.15.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20090515112424-b74i26lciabf4qnk
Tags: 1.1.75+svn968012-1
* New upstream development snapshot:
  - Last Changed Author: hein
  - Last Changed Rev: 968012
  - Last Changed Date: 2009-05-14 21:03:55 +0300
* Update README.source.
* Use dh --quilt instead of custom patch handling, build depend on
  quilt 0.46-7~.
* Update patches to upstream changes.
* Update konversation.install: remove docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
}
91
91
 
92
92
// fill listview with autoreplace definitions
93
 
void Autoreplace_Config::setAutoreplaceListView(const QStringList &autoreplaceList)
 
93
void Autoreplace_Config::setAutoreplaceListView(const QList<QStringList> &autoreplaceList)
94
94
{
95
95
  // clear listView
96
96
  patternListView->clear();
97
97
  // go through the list
98
 
  for(unsigned int index=autoreplaceList.count();index!=0;index--)
 
98
  for (int index=0;index<autoreplaceList.count();index++)
99
99
  {
100
100
    // get autoreplace definition
101
 
    QString definition=autoreplaceList[index-1];
 
101
    QStringList definition=autoreplaceList[index];
102
102
    // cut definition apart in name and action, and create a new listview item
103
103
    QTreeWidgetItem* newItem=new QTreeWidgetItem(patternListView);
104
104
    newItem->setFlags(newItem->flags() &~ Qt::ItemIsDropEnabled);
105
 
    newItem->setCheckState(0, Qt::Checked);
 
105
    newItem->setCheckState(0, Qt::Unchecked);
106
106
    // Regular expression?
107
 
    if(definition.section(',',0,0)=="1") newItem->setCheckState(0, Qt::Checked);
 
107
    if (definition.at(0)=="1") newItem->setCheckState(0, Qt::Checked);
108
108
    // direction input/output/both
109
 
    if(definition.section(',',1,1)=="i") newItem->setText(1,directionCombo->itemText(DIRECTION_INPUT));
110
 
    else if(definition.section(',',1,1)=="o") newItem->setText(1,directionCombo->itemText(DIRECTION_OUTPUT));
111
 
    else if(definition.section(',',1,1)=="io") newItem->setText(1,directionCombo->itemText(DIRECTION_BOTH));
 
109
    if (definition.at(1)=="i") 
 
110
    {
 
111
        newItem->setText(1,directionCombo->itemText(DIRECTION_INPUT));
 
112
    }
 
113
    else if (definition.at(1)=="o")
 
114
    {
 
115
        newItem->setText(1,directionCombo->itemText(DIRECTION_OUTPUT));
 
116
    }
 
117
    else if (definition.at(1)=="io")
 
118
    {
 
119
        newItem->setText(1,directionCombo->itemText(DIRECTION_BOTH));
 
120
    }
112
121
    // pattern
113
 
    newItem->setText(2,definition.section(',',2,2));
 
122
    newItem->setText(2,definition.at(2));
114
123
    // replacement
115
 
    newItem->setText(3,definition.section(',',3));
 
124
    newItem->setText(3,definition.at(3));
116
125
    // hidden column, so we are independent of the i18n()ed display string
117
 
    newItem->setText(4,definition.section(',',1,1));
 
126
    newItem->setText(4,definition.at(1));
118
127
  } // for
119
128
  patternListView->setCurrentItem(patternListView->topLevelItem(0));
120
129
}
132
141
  KConfigGroup grp = config->group("Autoreplace List");
133
142
 
134
143
  // create empty list
135
 
  QStringList newList=currentAutoreplaceList();
 
144
  QList<QStringList> newList=currentAutoreplaceList();
136
145
 
137
146
  // check if there are any patterns in the list view
138
147
  if(newList.count())
139
148
  {
140
149
    // go through all patterns and save them into the configuration
 
150
    QString regexString("Regex");
 
151
    QString directString("Direction");
 
152
    QString patternString("Pattern");
 
153
    QString replaceString("Replace");
141
154
    for(int index=0;index<newList.count();index++)
142
155
    {
143
 
      // write the current entry's pattern and replacement (adds a "#" to preserve blanks at the end of the line)
144
 
     grp.writeEntry(QString("Autoreplace%1").arg(index),newList[index]+'#');
 
156
        // write the current entry's pattern and replacement (adds a "#" to preserve blanks at the end of the line)
 
157
        QString indexString(QString::number(index));
 
158
        QStringList definition = newList[index];
 
159
        grp.writeEntry(regexString + indexString,definition.at(0)); //regex status
 
160
        grp.writeEntry(directString + indexString,definition.at(1)); //direction
 
161
        grp.writeEntry(patternString + indexString,definition.at(2)+'#'); //pattern
 
162
        grp.writeEntry(replaceString + indexString,definition.at(3)+'#'); //replace
 
163
        
145
164
    } // for
146
165
  }
147
166
  // if there were no entries at all, write a dummy entry to prevent KConfigXT from "optimizing"
161
180
  setAutoreplaceListView(Preferences::defaultAutoreplaceList());
162
181
}
163
182
 
164
 
QStringList Autoreplace_Config::currentAutoreplaceList()
 
183
QList<QStringList> Autoreplace_Config::currentAutoreplaceList()
165
184
{
166
185
  // get first item of the autoreplace listview
167
186
  QTreeWidgetItem* item=patternListView->topLevelItem(0);
168
187
  // create empty list
169
 
  QStringList newList;
 
188
  QList<QStringList> newList;
170
189
 
171
190
  // go through all items and save them into the configuration
172
191
  while(item)
173
192
  {
174
 
    QString checked="0";
175
 
    if(static_cast<QTreeWidgetItem*>(item)->checkState(0) == Qt::Checked) checked="1";
 
193
    QString regex="0";
 
194
    if (static_cast<QTreeWidgetItem*>(item)->checkState(0) == Qt::Checked) regex="1";
176
195
 
177
196
    // remember entry in internal list (col 4 is hidden for input/output)
178
 
    newList.append(checked+','+item->text(4)+','+item->text(2)+','+item->text(3));
 
197
    newList.append(QStringList() << regex << item->text(4) << item->text(2) << item->text(3));
179
198
    // get next item in the listview
180
199
    item=patternListView->itemBelow(item);
181
200
  } // while
272
291
  if(item)
273
292
  {
274
293
    // rename pattern
275
 
    item->setText(2,newPattern);
 
294
    if (newPattern.length()>0)
 
295
    {
 
296
        item->setText(2,newPattern);
 
297
    }
 
298
    else
 
299
    {
 
300
        item->setText(2,QString("New"));
 
301
    }
276
302
    // tell the config system that something has changed
277
303
    if(!m_newItemSelected) emit modified();
278
304
  }