~ubuntu-branches/ubuntu/karmic/uim/karmic-proposed

« back to all changes in this revision

Viewing changes to qt/candwin-qt.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2009-03-01 12:57:00 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090301125700-0ykjdq0zgj55e3n3
Tags: 1:1.5.5-1
New upstream release and final upload by current maintainter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
 Copyright (c) 2003-2008 uim Project http://code.google.com/p/uim/
 
3
 Copyright (c) 2003-2009 uim Project http://code.google.com/p/uim/
4
4
 
5
5
 All rights reserved.
6
6
 
248
248
    hide();
249
249
    isActive = false;
250
250
}
 
251
void CandidateWindow::setNrCandidates( const QStringList &list )
 
252
{
 
253
#if defined(ENABLE_DEBUG)
 
254
    qDebug( "uim-candwin-qt: setNrCandidates()" );
 
255
#endif
 
256
    if ( list[ 1 ].isEmpty() || list[ 2 ].isEmpty() )
 
257
        return ;
 
258
 
 
259
    // remove old data
 
260
    cList->clear();
 
261
    stores.clear();
 
262
 
 
263
    // set default value
 
264
    candidateIndex = -1;
 
265
    nrCandidates = list[ 1 ].toInt();
 
266
    displayLimit = list[ 2 ].toInt();
 
267
    needHilite = false;
 
268
    isActive = true;
 
269
 
 
270
    // setup dummy stores
 
271
    for ( int i = 0; i < nrCandidates; i++ ) {
 
272
        CandData d;
 
273
        stores.append( d );
 
274
    }
 
275
}
 
276
void CandidateWindow::setPageCandidates( const QStringList &list )
 
277
{
 
278
#if defined(ENABLE_DEBUG)
 
279
    qDebug( "uim-candwin-qt: setPageCandidates()" );
 
280
#endif
 
281
    /**
 
282
     * format: set_page_candidates\ncharset=$charset\npage=$value\nhead1\tcand1\nhead2\tcand2\nhead3\tcand3\n
 
283
     */
 
284
 
 
285
    int page = 0;
 
286
 
 
287
    // get charset and create codec
 
288
    QTextCodec *codec = NULL;
 
289
    if ( !list[ 1 ].isEmpty() && list[ 1 ].startsWith( "charset" ) )
 
290
    {
 
291
        const QStringList l = QStringList::split( "=", list[ 1 ] );
 
292
        codec = QTextCodec::codecForName( l[ 1 ] );
 
293
    }
 
294
 
 
295
    // get page
 
296
    if ( !list[ 2 ].isEmpty() && list[ 2 ].startsWith( "page" ) )
 
297
    {
 
298
        const QStringList l = QStringList::split( "=", list[ 2 ] );
 
299
        page = l[ 1 ].toInt();
 
300
    }
 
301
 
 
302
    for ( int i = 3; !list[ i ].isNull(); i++ )
 
303
    {
 
304
        // case list[i] = ""
 
305
        if ( list[ i ].isEmpty() )
 
306
            break;
 
307
 
 
308
        // split heading_label and cand_str
 
309
        QStringList l = QStringList::split( "\t", list [ i ], true );
 
310
 
 
311
        // store data
 
312
        CandData &d = stores[page * displayLimit + i - 3];
 
313
        QString headString;
 
314
        if ( codec )
 
315
            headString = codec->toUnicode( l [ 0 ] );
 
316
        else
 
317
            headString = l [ 0 ];
 
318
 
 
319
        d.label = headString;
 
320
 
 
321
        // XXX Current prime (0.4.6) may return candidate string
 
322
        // containing "\t", and we can't handle annotation in another
 
323
        // window yet.
 
324
        l.pop_front();
 
325
        QString candString = l.join( "\t" );
 
326
 
 
327
        if ( codec )
 
328
            d.str = codec->toUnicode( candString );
 
329
        else
 
330
            d.str = candString;
 
331
    }
 
332
}
 
333
void CandidateWindow::showPage( const QStringList &list )
 
334
{
 
335
#if defined(ENABLE_DEBUG)
 
336
    qDebug( "uim-candwin-qt: showPage()" );
 
337
#endif
 
338
    const int page = list[ 1 ].toInt();
 
339
 
 
340
    setPage( page );
 
341
    adjustCandidateWindowSize();
 
342
    show();
 
343
}
251
344
void CandidateWindow::slotStdinActivated( int fd )
252
345
{
253
346
    char buf[ 4096 ];
300
393
            moveCand( list );
301
394
        else if ( QString::compare( "deactivate", ( *it ) ) == 0 )
302
395
            deactivateCand();
 
396
        else if ( QString::compare( "set_nr_candidates", ( *it ) ) == 0 )
 
397
            setNrCandidates( list );
 
398
        else if ( QString::compare( "set_page_candidates", ( *it ) ) == 0 )
 
399
            setPageCandidates( list );
 
400
        else if ( QString::compare( "show_page", ( *it ) ) == 0 )
 
401
            showPage( list );
303
402
    }
304
403
}
305
404