~ubuntu-branches/ubuntu/wily/apvlv/wily

« back to all changes in this revision

Viewing changes to src/ApvlvDir.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-06-01 22:18:49 UTC
  • mfrom: (10.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110601221849-niibd5p5i7avemy4
Tags: 0.1.1-1.1
* Non-maintainer upload.
* Add support for poppler >= 0.15. Patch by Pino Toscano. (Closes: #627609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "ApvlvParams.hpp"
31
31
#include "ApvlvDir.hpp"
32
32
 
33
 
#include <stdlib.h>
34
 
#include <errno.h>
35
 
#include <string.h>
36
 
#include <math.h>
37
 
#include <sys/stat.h>
38
 
 
39
33
#include <gtk/gtk.h>
40
34
#include <gdk/gdkkeysyms.h>
41
35
#include <glib/gstdio.h>
42
36
 
 
37
#include <cerrno>
 
38
#include <sys/stat.h>
43
39
#include <iostream>
44
40
#include <fstream>
45
41
#include <sstream>
46
42
 
47
43
namespace apvlv
48
 
{
 
44
  {
49
45
  ApvlvDirNode::ApvlvDirNode (GtkTreeIter * ir, gint p)
50
46
  {
51
47
    *itr = *ir;
54
50
  }
55
51
 
56
52
  ApvlvDirNode::ApvlvDirNode (GtkTreeIter * ir, bool isdir, const char *real,
57
 
                              const char *file)
 
53
                              const char *file)
58
54
  {
59
55
    *itr = *ir;
60
56
    mPagenum = isdir ? -1 : 0;
66
62
  {
67
63
    if (realname)
68
64
      {
69
 
        g_free (realname);
 
65
        g_free (realname);
70
66
      }
71
67
  }
72
68
 
74
70
  {
75
71
    if (mPagenum == 0 && path != NULL)
76
72
      {
77
 
        *path = realname;
78
 
        return true;
 
73
        *path = realname;
 
74
        return true;
79
75
      }
80
76
 
81
77
    else if (mPagenum > 0 && pn != NULL)
82
78
      {
83
 
        *pn = mPagenum;
84
 
        return true;
 
79
        *pn = mPagenum;
 
80
        return true;
85
81
      }
86
82
 
87
83
    return false;
119
115
 
120
116
    mSelection = gtk_tree_view_get_selection (GTK_TREE_VIEW (mDirView));
121
117
    g_signal_connect (G_OBJECT (mSelection), "changed",
122
 
                      G_CALLBACK (apvlv_dir_on_changed), this);
 
118
                      G_CALLBACK (apvlv_dir_on_changed), this);
123
119
 
124
120
    /* Title Column */
125
121
    GtkCellRenderer *renderer0 = gtk_cell_renderer_pixbuf_new ();
148
144
 
149
145
    if (mDirNodes)
150
146
      {
151
 
        for (GList * list = mDirNodes; list; list = g_list_next (list))
152
 
          {
153
 
            ApvlvDirNode *info = (ApvlvDirNode *) list->data;
154
 
            delete info;
155
 
          }
156
 
        g_list_free (mDirNodes);
157
 
        mDirNodes = NULL;
 
147
        for (GList * list = mDirNodes; list; list = g_list_next (list))
 
148
          {
 
149
            ApvlvDirNode *info = (ApvlvDirNode *) list->data;
 
150
            delete info;
 
151
          }
 
152
        g_list_free (mDirNodes);
 
153
        mDirNodes = NULL;
158
154
      }
159
155
 
160
156
    if (mIndex != NULL)
161
157
      {
162
 
        mFile->free_index (mIndex);
163
 
        mIndex = NULL;
 
158
        mFile->free_index (mIndex);
 
159
        mIndex = NULL;
164
160
      }
165
161
 
166
162
    if (mFile != NULL)
167
163
      {
168
 
        delete mFile;
169
 
        mFile = NULL;
 
164
        delete mFile;
 
165
        mFile = NULL;
170
166
      }
171
167
 
172
168
    loadfile (mFilestr.c_str (), FALSE);
179
175
    gchar *rpath;
180
176
 
181
177
    if (path == NULL
182
 
        || *path == '\0'
183
 
        || (rpath = g_locale_from_utf8 (path, -1, NULL, NULL, NULL)) == NULL)
 
178
        || *path == '\0'
 
179
        || (rpath = g_locale_from_utf8 (path, -1, NULL, NULL, NULL)) == NULL)
184
180
      {
185
 
        gView->errormessage ("path error: %s", path ? path : "No path");
186
 
        return false;
 
181
        gView->errormessage ("path error: %s", path ? path : "No path");
 
182
        return false;
187
183
      }
188
184
 
189
185
    struct stat buf[1];
191
187
    g_free (rpath);
192
188
    if (ret < 0)
193
189
      {
194
 
        gView->errormessage ("stat error: %d:%s", errno, strerror (errno));
195
 
        return false;
 
190
        gView->errormessage ("stat error: %d:%s", errno, strerror (errno));
 
191
        return false;
196
192
      }
197
193
 
198
194
    if (S_ISDIR (buf->st_mode))
199
195
      {
200
 
        mReady = walk_dir_path_index (NULL, path);
 
196
        mReady = walk_dir_path_index (NULL, path);
201
197
      }
202
198
    else
203
199
      {
204
 
        mFile = ApvlvFile::newfile (path);
 
200
        mFile = ApvlvFile::newfile (path);
205
201
 
206
 
        if (mFile != NULL && (mIndex = mFile->new_index ()) != NULL)
207
 
          {
208
 
            for (ApvlvFileIndexIter itr = mIndex->children.begin ();
209
 
                 itr != mIndex->children.end (); ++itr)
210
 
              {
211
 
                bool ready = walk_file_index (NULL, itr);
212
 
                if (mReady == false)
213
 
                  {
214
 
                    mReady = ready;
215
 
                  }
216
 
              }
217
 
          }
218
 
        else
219
 
          {
220
 
            mReady = false;
221
 
          }
 
202
        if (mFile != NULL && (mIndex = mFile->new_index ()) != NULL)
 
203
          {
 
204
            for (ApvlvFileIndexIter itr = mIndex->children.begin ();
 
205
                 itr != mIndex->children.end (); ++itr)
 
206
              {
 
207
                bool ready = walk_file_index (NULL, itr);
 
208
                if (mReady == false)
 
209
                  {
 
210
                    mReady = ready;
 
211
                  }
 
212
              }
 
213
          }
 
214
        else
 
215
          {
 
216
            mReady = false;
 
217
          }
222
218
      }
223
219
 
224
220
    if (mReady)
225
221
      {
226
 
        mFilestr = path;
227
 
        mFirstSelTimer =
228
 
          g_timeout_add (50,
229
 
                         (gboolean (*)(gpointer)) apvlv_dir_first_select_cb,
230
 
                         this);
 
222
        mFilestr = path;
 
223
        mFirstSelTimer =
 
224
          g_timeout_add (50,
 
225
                         (gboolean (*)(gpointer)) apvlv_dir_first_select_cb,
 
226
                         this);
231
227
      }
232
228
 
233
229
    return mReady;
237
233
  {
238
234
    if (mDirNodes)
239
235
      {
240
 
        for (GList * list = mDirNodes; list; list = g_list_next (list))
241
 
          {
242
 
            ApvlvDirNode *info = (ApvlvDirNode *) list->data;
243
 
            delete info;
244
 
          }
245
 
        g_list_free (mDirNodes);
 
236
        for (GList * list = mDirNodes; list; list = g_list_next (list))
 
237
          {
 
238
            ApvlvDirNode *info = (ApvlvDirNode *) list->data;
 
239
            delete info;
 
240
          }
 
241
        g_list_free (mDirNodes);
246
242
      }
247
243
 
248
244
    if (mIndex != NULL)
249
245
      {
250
 
        mFile->free_index (mIndex);
 
246
        mFile->free_index (mIndex);
251
247
      }
252
248
 
253
249
    if (mFile != NULL)
254
250
      {
255
 
        delete mFile;
 
251
        delete mFile;
256
252
      }
257
253
 
258
254
    delete mStatus;
265
261
    switch (procmd)
266
262
      {
267
263
      default:
268
 
        return NO_MATCH;
269
 
        break;
 
264
        return NO_MATCH;
 
265
        break;
270
266
      }
271
267
 
272
268
    return MATCH;
276
272
  {
277
273
    if (ct == 0)
278
274
      {
279
 
        ct++;
 
275
        ct++;
280
276
      }
281
277
 
282
278
    if (mProCmd != 0)
283
279
      {
284
 
        return subprocess (ct, key);
 
280
        return subprocess (ct, key);
285
281
      }
286
282
 
287
283
    switch (key)
289
285
      case ':':
290
286
      case '/':
291
287
      case '?':
292
 
        gView->promptcommand (key);
293
 
        return NEED_MORE;
 
288
        gView->promptcommand (key);
 
289
        return NEED_MORE;
294
290
 
295
291
      case 'n':
296
 
        markposition ('\'');
297
 
        search ("");
298
 
        break;
 
292
        markposition ('\'');
 
293
        search ("");
 
294
        break;
299
295
      case 'N':
300
 
        markposition ('\'');
301
 
        search ("", true);
302
 
        break;
 
296
        markposition ('\'');
 
297
        search ("", true);
 
298
        break;
303
299
 
304
300
      case 't':
305
301
      case 'o':
306
302
      case GDK_Return:
307
 
        enter (key);
308
 
        break;
 
303
        enter (key);
 
304
        break;
309
305
 
310
306
      case 'H':
311
 
        scrollto (0.0);
312
 
        break;
 
307
        scrollto (0.0);
 
308
        break;
313
309
      case 'M':
314
 
        scrollto (0.5);
315
 
        break;
 
310
        scrollto (0.5);
 
311
        break;
316
312
      case 'L':
317
 
        scrollto (1.0);
318
 
        break;
 
313
        scrollto (1.0);
 
314
        break;
319
315
 
320
316
      case GDK_Up:
321
317
      case 'k':
322
 
        scrollup (ct);
323
 
        break;
 
318
        scrollup (ct);
 
319
        break;
324
320
 
325
321
      case CTRL ('n'):
326
322
      case CTRL ('j'):
327
323
      case GDK_Down:
328
324
      case 'j':
329
 
        scrolldown (ct);
330
 
        break;
 
325
        scrolldown (ct);
 
326
        break;
331
327
 
332
328
      case GDK_BackSpace:
333
329
      case GDK_Left:
334
330
      case CTRL ('h'):
335
331
      case 'h':
336
 
        scrollleft (ct);
337
 
        break;
 
332
        scrollleft (ct);
 
333
        break;
338
334
 
339
335
      case GDK_space:
340
336
      case GDK_Right:
341
337
      case CTRL ('l'):
342
338
      case 'l':
343
 
        scrollright (ct);
344
 
        break;
 
339
        scrollright (ct);
 
340
        break;
345
341
 
346
342
      case 'R':
347
 
        reload ();
348
 
        break;
 
343
        reload ();
 
344
        break;
349
345
      }
350
346
 
351
347
    return MATCH;
358
354
    gtk_tree_model_get (GTK_TREE_MODEL (mStore), &mCurrentIter, 0, &node, -1);
359
355
    if (node == NULL)
360
356
      {
361
 
        return false;
 
357
        return false;
362
358
      }
363
359
 
364
360
    const char *name = NULL;
365
361
    int pn = -1;
366
362
    if (!node->dest (&name, &pn))
367
363
      {
368
 
        return false;
 
364
        return false;
369
365
      }
370
366
 
371
367
    ApvlvCore *ndoc = NULL;
372
368
    if (name != NULL)
373
369
      {
374
 
        if (gParams->valueb ("content"))
375
 
          {
376
 
            ndoc = new ApvlvDir (mWidth, mHeight);
377
 
            if (!ndoc->loadfile (name))
378
 
              {
379
 
                delete ndoc;
380
 
                ndoc = NULL;
381
 
              }
382
 
          }
 
370
        if (gParams->valueb ("content"))
 
371
          {
 
372
            ndoc = new ApvlvDir (mWidth, mHeight);
 
373
            if (!ndoc->loadfile (name))
 
374
              {
 
375
                delete ndoc;
 
376
                ndoc = NULL;
 
377
              }
 
378
          }
383
379
 
384
 
        if (ndoc == NULL)
385
 
          {
386
 
            ndoc =
387
 
              new ApvlvDoc (mWidth, mHeight, gParams->values ("zoom"),
388
 
                            gParams->valueb ("cache"));
389
 
            if (!ndoc->loadfile (name))
390
 
              {
391
 
                delete ndoc;
392
 
                ndoc = NULL;
393
 
              }
394
 
          }
 
380
        if (ndoc == NULL)
 
381
          {
 
382
            ndoc =
 
383
              new ApvlvDoc (mWidth, mHeight, gParams->values ("zoom"),
 
384
                            gParams->valueb ("cache"));
 
385
            if (!ndoc->loadfile (name))
 
386
              {
 
387
                delete ndoc;
 
388
                ndoc = NULL;
 
389
              }
 
390
          }
395
391
      }
396
392
    else
397
393
      {
398
 
        ndoc =
399
 
          new ApvlvDoc (mWidth, mHeight, gParams->values ("zoom"),
400
 
                        gParams->valueb ("cache"));
401
 
        if (!ndoc->loadfile (filename ()))
402
 
          {
403
 
            delete ndoc;
404
 
            ndoc = NULL;
405
 
          }
 
394
        ndoc =
 
395
          new ApvlvDoc (mWidth, mHeight, gParams->values ("zoom"),
 
396
                        gParams->valueb ("cache"));
 
397
        if (!ndoc->loadfile (filename ()))
 
398
          {
 
399
            delete ndoc;
 
400
            ndoc = NULL;
 
401
          }
406
402
 
407
 
        if (ndoc != NULL)
408
 
          {
409
 
            ((ApvlvDoc *) ndoc)->showpage (pn);
410
 
          }
 
403
        if (ndoc != NULL)
 
404
          {
 
405
            ((ApvlvDoc *) ndoc)->showpage (pn);
 
406
          }
411
407
      }
412
408
 
413
409
    if (ndoc == NULL)
414
410
      {
415
 
        return false;
 
411
        return false;
416
412
      }
417
413
 
418
414
    gView->regloaded (ndoc);
420
416
    switch (key)
421
417
      {
422
418
      case GDK_Return:
423
 
        ApvlvWindow::currentWindow ()->setCore (ndoc);
424
 
        break;
 
419
        ApvlvWindow::currentWindow ()->setCore (ndoc);
 
420
        break;
425
421
 
426
422
      case 'o':
427
 
        ApvlvWindow::currentWindow ()->birth (false, ndoc);
428
 
        break;
 
423
        ApvlvWindow::currentWindow ()->birth (false, ndoc);
 
424
        break;
429
425
 
430
426
      case 't':
431
 
        gView->newtab (ndoc);
432
 
        break;
 
427
        gView->newtab (ndoc);
 
428
        break;
433
429
 
434
430
      default:
435
 
        return false;
 
431
        return false;
436
432
      }
437
433
 
438
434
    return true;
443
439
    GtkTreePath *path;
444
440
 
445
441
    if (!mReady
446
 
        || (path =
447
 
            gtk_tree_model_get_path (GTK_TREE_MODEL (mStore),
448
 
                                     &mCurrentIter)) == NULL)
 
442
        || (path =
 
443
              gtk_tree_model_get_path (GTK_TREE_MODEL (mStore),
 
444
                                       &mCurrentIter)) == NULL)
449
445
      {
450
 
        return;
 
446
        return;
451
447
      }
452
448
 
453
449
    for (gboolean ret = TRUE; times > 0 && ret; times--)
454
450
      {
455
 
        ret = gtk_tree_path_prev (path);
 
451
        ret = gtk_tree_path_prev (path);
456
452
      }
457
453
 
458
454
    gtk_tree_model_get_iter (GTK_TREE_MODEL (mStore), &mCurrentIter, path);
459
455
    gtk_tree_selection_select_iter (mSelection, &mCurrentIter);
460
456
    gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL, TRUE,
461
 
                                  0.5, 0.0);
 
457
                                  0.5, 0.0);
462
458
    gtk_tree_path_free (path);
463
459
 
464
460
    mStatus->show ();
474
470
 
475
471
    for (ret = TRUE, itr = mCurrentIter; times > 0 && ret; times--)
476
472
      {
477
 
        mCurrentIter = itr;
478
 
        ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (mStore), &itr);
479
 
        if (ret)
480
 
          {
481
 
            mCurrentIter = itr;
482
 
          }
 
473
        mCurrentIter = itr;
 
474
        ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (mStore), &itr);
 
475
        if (ret)
 
476
          {
 
477
            mCurrentIter = itr;
 
478
          }
483
479
      }
484
480
 
485
481
    gtk_tree_selection_select_iter (mSelection, &mCurrentIter);
488
484
      gtk_tree_model_get_path (GTK_TREE_MODEL (mStore), &mCurrentIter);
489
485
    if (path)
490
486
      {
491
 
        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL,
492
 
                                      TRUE, 0.5, 0.0);
493
 
        gtk_tree_path_free (path);
 
487
        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL,
 
488
                                      TRUE, 0.5, 0.0);
 
489
        gtk_tree_path_free (path);
494
490
      }
495
491
 
496
492
    mStatus->show ();
504
500
    GtkTreeIter itr;
505
501
    for (gboolean ret = TRUE; times > 0 && ret; times--)
506
502
      {
507
 
        ret =
508
 
          gtk_tree_model_iter_parent (GTK_TREE_MODEL (mStore), &itr,
509
 
                                      &mCurrentIter);
510
 
        if (ret)
511
 
          {
512
 
            mCurrentIter = itr;
513
 
          }
 
503
        ret =
 
504
          gtk_tree_model_iter_parent (GTK_TREE_MODEL (mStore), &itr,
 
505
                                      &mCurrentIter);
 
506
        if (ret)
 
507
          {
 
508
            mCurrentIter = itr;
 
509
          }
514
510
      }
515
511
 
516
512
    gtk_tree_selection_select_iter (mSelection, &mCurrentIter);
519
515
      gtk_tree_model_get_path (GTK_TREE_MODEL (mStore), &mCurrentIter);
520
516
    if (path)
521
517
      {
522
 
        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL,
523
 
                                      TRUE, 0.5, 0.0);
524
 
        gtk_tree_view_collapse_row (GTK_TREE_VIEW (mDirView), path);
525
 
        gtk_tree_path_free (path);
 
518
        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL,
 
519
                                      TRUE, 0.5, 0.0);
 
520
        gtk_tree_view_collapse_row (GTK_TREE_VIEW (mDirView), path);
 
521
        gtk_tree_path_free (path);
526
522
      }
527
523
 
528
524
    mStatus->show ();
536
532
    GtkTreeIter itr;
537
533
    for (gboolean ret = TRUE; times > 0 && ret; times--)
538
534
      {
539
 
        ret =
540
 
          gtk_tree_model_iter_children (GTK_TREE_MODEL (mStore), &itr,
541
 
                                        &mCurrentIter);
542
 
        if (ret)
543
 
          {
544
 
            mCurrentIter = itr;
545
 
          }
 
535
        ret =
 
536
          gtk_tree_model_iter_children (GTK_TREE_MODEL (mStore), &itr,
 
537
                                        &mCurrentIter);
 
538
        if (ret)
 
539
          {
 
540
            mCurrentIter = itr;
 
541
          }
546
542
      }
547
543
 
548
544
    GtkTreePath *path =
549
545
      gtk_tree_model_get_path (GTK_TREE_MODEL (mStore), &mCurrentIter);
550
546
    if (path)
551
547
      {
552
 
        gtk_tree_view_expand_to_path (GTK_TREE_VIEW (mDirView), path);
553
 
        gtk_tree_selection_select_iter (mSelection, &mCurrentIter);
554
 
        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL,
555
 
                                      TRUE, 0.5, 0.0);
556
 
        gtk_tree_path_free (path);
 
548
        gtk_tree_view_expand_to_path (GTK_TREE_VIEW (mDirView), path);
 
549
        gtk_tree_selection_select_iter (mSelection, &mCurrentIter);
 
550
        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL,
 
551
                                      TRUE, 0.5, 0.0);
 
552
        gtk_tree_path_free (path);
557
553
      }
558
554
 
559
555
    mStatus->show ();
568
564
 
569
565
    if (*str == '\0' && mSearchStr == "")
570
566
      {
571
 
        return false;
 
567
        return false;
572
568
      }
573
569
 
574
570
    next = true;
575
571
    if (*str != '\0')
576
572
      {
577
 
        mSearchStr = str;
578
 
        next = false;
 
573
        mSearchStr = str;
 
574
        next = false;
579
575
      }
580
576
 
581
577
    ApvlvDirNode *info = NULL;
582
578
    gtk_tree_model_get (GTK_TREE_MODEL (mStore), &mCurrentIter, 0, &info, -1);
583
579
    if (info == NULL || mDirNodes == NULL)
584
580
      {
585
 
        gView->errormessage ("can't find word: '%s'", mSearchStr.c_str ());
586
 
        return false;
 
581
        gView->errormessage ("can't find word: '%s'", mSearchStr.c_str ());
 
582
        return false;
587
583
      }
588
584
 
589
585
    GList *list;
590
586
    for (list = mDirNodes; list; list = g_list_next (list))
591
587
      {
592
 
        if (info == list->data)
593
 
          {
594
 
            break;
595
 
          }
 
588
        if (info == list->data)
 
589
          {
 
590
            break;
 
591
          }
596
592
      }
597
593
 
598
594
    if (list == NULL)
599
595
      {
600
 
        gView->errormessage ("can't find word: '%s'", mSearchStr.c_str ());
601
 
        return false;
 
596
        gView->errormessage ("can't find word: '%s'", mSearchStr.c_str ());
 
597
        return false;
602
598
      }
603
599
 
604
600
    if (next)
605
601
      {
606
 
        if (reverse)
607
 
          {
608
 
            list = g_list_previous (list);
609
 
          }
610
 
        else
611
 
          {
612
 
            list = g_list_next (list);
613
 
          }
 
602
        if (reverse)
 
603
          {
 
604
            list = g_list_previous (list);
 
605
          }
 
606
        else
 
607
          {
 
608
            list = g_list_next (list);
 
609
          }
614
610
      }
615
611
 
616
612
    bool wrap = gParams->valueb ("wrapscan");
617
613
 
618
614
    for (GList * origin = list; list != NULL;)
619
615
      {
620
 
        info = (ApvlvDirNode *) list->data;
621
 
        if (strstr (info->phrase (), mSearchStr.c_str ()) != NULL)
622
 
          {
623
 
            break;
624
 
          }
625
 
 
626
 
        if (reverse)
627
 
          {
628
 
            list = g_list_previous (list);
629
 
          }
630
 
        else
631
 
          {
632
 
            list = g_list_next (list);
633
 
          }
634
 
 
635
 
        if (list == origin)
636
 
          {
637
 
            list = NULL;
638
 
            break;
639
 
          }
640
 
 
641
 
        if (list == NULL && wrap)
642
 
          {
643
 
            if (reverse)
644
 
              {
645
 
                list = g_list_last (mDirNodes);
646
 
              }
647
 
            else
648
 
              {
649
 
                list = mDirNodes;
650
 
              }
651
 
          }
 
616
        info = (ApvlvDirNode *) list->data;
 
617
        if (strstr (info->phrase (), mSearchStr.c_str ()) != NULL)
 
618
          {
 
619
            break;
 
620
          }
 
621
 
 
622
        if (reverse)
 
623
          {
 
624
            list = g_list_previous (list);
 
625
          }
 
626
        else
 
627
          {
 
628
            list = g_list_next (list);
 
629
          }
 
630
 
 
631
        if (list == origin)
 
632
          {
 
633
            list = NULL;
 
634
            break;
 
635
          }
 
636
 
 
637
        if (list == NULL && wrap)
 
638
          {
 
639
            if (reverse)
 
640
              {
 
641
                list = g_list_last (mDirNodes);
 
642
              }
 
643
            else
 
644
              {
 
645
                list = mDirNodes;
 
646
              }
 
647
          }
652
648
      }
653
649
 
654
650
    if (list == NULL)
655
651
      {
656
 
        gView->errormessage ("can't find word: '%s'", mSearchStr.c_str ());
657
 
        return false;
 
652
        gView->errormessage ("can't find word: '%s'", mSearchStr.c_str ());
 
653
        return false;
658
654
      }
659
655
 
660
656
    mCurrentIter = *info->iter ();
662
658
      gtk_tree_model_get_path (GTK_TREE_MODEL (mStore), &mCurrentIter);
663
659
    if (path)
664
660
      {
665
 
        gtk_tree_view_expand_to_path (GTK_TREE_VIEW (mDirView), path);
666
 
        gtk_tree_selection_select_iter (mSelection, &mCurrentIter);
667
 
        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL,
668
 
                                      TRUE, 0.5, 0.0);
669
 
        gtk_tree_path_free (path);
 
661
        gtk_tree_view_expand_to_path (GTK_TREE_VIEW (mDirView), path);
 
662
        gtk_tree_selection_select_iter (mSelection, &mCurrentIter);
 
663
        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (mDirView), path, NULL,
 
664
                                      TRUE, 0.5, 0.0);
 
665
        gtk_tree_path_free (path);
670
666
      }
671
667
 
672
668
    mStatus->show ();
691
687
    mDirNodes = g_list_append (mDirNodes, node);
692
688
 
693
689
    GdkPixbuf *pix = gdk_pixbuf_new_from_file_at_size (iconreg.c_str (), 40,
694
 
                                                       20, NULL);
 
690
                     20, NULL);
695
691
    if (pix)
696
692
      {
697
 
        gtk_tree_store_set (mStore, nitr, 0, node, 1, pix, 2,
698
 
                            iter->title.c_str (), -1);
699
 
        g_object_unref (pix);
 
693
        gtk_tree_store_set (mStore, nitr, 0, node, 1, pix, 2,
 
694
                            iter->title.c_str (), -1);
 
695
        g_object_unref (pix);
700
696
      }
701
697
    else
702
698
      {
703
 
        gtk_tree_store_set (mStore, nitr, 0, node, 2,
704
 
                            iter->title.c_str (), -1);
 
699
        gtk_tree_store_set (mStore, nitr, 0, node, 2,
 
700
                            iter->title.c_str (), -1);
705
701
      }
706
702
 
707
703
    for (ApvlvFileIndexIter itr = iter->children.begin ();
708
 
         itr != iter->children.end (); ++itr)
 
704
         itr != iter->children.end (); ++itr)
709
705
      {
710
 
        bool chas = walk_file_index (has ? nitr : titr, itr);
711
 
        if (has == false)
712
 
          {
713
 
            has = chas;
714
 
          }
 
706
        bool chas = walk_file_index (has ? nitr : titr, itr);
 
707
        if (has == false)
 
708
          {
 
709
            has = chas;
 
710
          }
715
711
      }
716
712
 
717
713
    return has;
718
714
  }
719
715
 
720
716
  void
721
 
    ApvlvDir::apvlv_dir_on_changed (GtkTreeSelection * selection,
722
 
                                    ApvlvDir * dir)
 
717
  ApvlvDir::apvlv_dir_on_changed (GtkTreeSelection * selection,
 
718
                                  ApvlvDir * dir)
723
719
  {
724
720
    GtkTreeModel *model;
725
721
    gtk_tree_selection_get_selected (selection, &model, &dir->mCurrentIter);
730
726
    mDoc = doc;
731
727
    for (int i = 0; i < AD_STATUS_SIZE; ++i)
732
728
      {
733
 
        mStlab[i] = gtk_label_new ("");
734
 
        gtk_box_pack_start (GTK_BOX (mHbox), mStlab[i], FALSE, FALSE, 0);
 
729
        mStlab[i] = gtk_label_new ("");
 
730
        gtk_box_pack_start (GTK_BOX (mHbox), mStlab[i], FALSE, FALSE, 0);
735
731
      }
736
732
  }
737
733
 
743
739
  {
744
740
    for (unsigned int i = 0; i < AD_STATUS_SIZE; ++i)
745
741
      {
746
 
        gtk_widget_modify_fg (mStlab[i],
747
 
                              (act) ? GTK_STATE_ACTIVE :
748
 
                              GTK_STATE_INSENSITIVE, NULL);
 
742
        gtk_widget_modify_fg (mStlab[i],
 
743
                              (act) ? GTK_STATE_ACTIVE :
 
744
                              GTK_STATE_INSENSITIVE, NULL);
749
745
      }
750
746
  }
751
747
 
758
754
    sw[3] = sw[1] >> 1;
759
755
    for (unsigned int i = 0; i < AD_STATUS_SIZE; ++i)
760
756
      {
761
 
        gtk_widget_set_size_request (mStlab[i], sw[i], h);
 
757
        gtk_widget_set_size_request (mStlab[i], sw[i], h);
762
758
      }
763
759
  }
764
760
 
766
762
  {
767
763
    if (mDoc->filename ())
768
764
      {
769
 
        char temp[AD_STATUS_SIZE][256];
770
 
        gchar *bn;
771
 
        bn = g_path_get_basename (mDoc->filename ());
772
 
        g_snprintf (temp[0], sizeof temp[0], "%s", bn);
773
 
        g_snprintf (temp[1], sizeof temp[1], "apvlv");
774
 
        g_snprintf (temp[2], sizeof temp[2], "%d%%",
775
 
                    (int) (mDoc->zoomvalue () * 100));
776
 
        g_snprintf (temp[3], sizeof temp[3], "%d%%",
777
 
                    (int) (mDoc->scrollrate () * 100));
778
 
        for (unsigned int i = 0; i < AD_STATUS_SIZE; ++i)
779
 
          {
780
 
            gtk_label_set_text (GTK_LABEL (mStlab[i]), temp[i]);
781
 
          }
782
 
        g_free (bn);
 
765
        char temp[AD_STATUS_SIZE][256];
 
766
        gchar *bn;
 
767
        bn = g_path_get_basename (mDoc->filename ());
 
768
        g_snprintf (temp[0], sizeof temp[0], "%s", bn);
 
769
        g_snprintf (temp[1], sizeof temp[1], "apvlv");
 
770
        g_snprintf (temp[2], sizeof temp[2], "%d%%",
 
771
                    (int) (mDoc->zoomvalue () * 100));
 
772
        g_snprintf (temp[3], sizeof temp[3], "%d%%",
 
773
                    (int) (mDoc->scrollrate () * 100));
 
774
        for (unsigned int i = 0; i < AD_STATUS_SIZE; ++i)
 
775
          {
 
776
            gtk_label_set_text (GTK_LABEL (mStlab[i]), temp[i]);
 
777
          }
 
778
        g_free (bn);
783
779
      }
784
780
  }
785
781
 
788
784
    GtkTreeIter gtir;
789
785
    if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dir->mStore), &gtir))
790
786
      {
791
 
        gtk_tree_selection_select_iter (dir->mSelection, &gtir);
 
787
        gtk_tree_selection_select_iter (dir->mSelection, &gtir);
792
788
      }
793
789
    return FALSE;
794
790
  }
799
795
    GDir *dir = g_dir_open (path, 0, NULL);
800
796
    if (dir != NULL)
801
797
      {
802
 
        const gchar *name;
803
 
        while ((name = g_dir_read_name (dir)) != NULL)
804
 
          {
805
 
            if (strcmp (name, ".") == 0)
806
 
              {
807
 
                debug ("avoid hidden file: %s", name);
808
 
                continue;
809
 
              }
 
798
        const gchar *name;
 
799
        while ((name = g_dir_read_name (dir)) != NULL)
 
800
          {
 
801
            if (strcmp (name, ".") == 0)
 
802
              {
 
803
                debug ("avoid hidden file: %s", name);
 
804
                continue;
 
805
              }
810
806
 
811
 
            gchar *realname = g_strjoin (PATH_SEP_S, path, name, NULL);
 
807
            gchar *realname = g_strjoin (PATH_SEP_S, path, name, NULL);
812
808
//          debug ("add a item: %s[%s]", name, realname);
813
809
 
814
 
            ApvlvDirNode *node = NULL;
815
 
            struct stat buf[1];
816
 
            char *wrealname =
817
 
              g_locale_from_utf8 (realname, -1, NULL, NULL, NULL);
818
 
            if (wrealname == NULL)
819
 
              {
820
 
                g_free (realname);
821
 
                continue;
822
 
              }
823
 
 
824
 
            int ret = stat (wrealname, buf);
825
 
            g_free (wrealname);
826
 
 
827
 
            if (ret < 0)
828
 
              {
829
 
                g_free (realname);
830
 
                continue;
831
 
              }
832
 
 
833
 
            if (S_ISDIR (buf->st_mode))
834
 
              {
835
 
                GtkTreeIter mitr[1];
836
 
                gtk_tree_store_append (mStore, mitr, itr);
837
 
                node = new ApvlvDirNode (mitr, true, realname, name);
838
 
 
839
 
                GdkPixbuf *pix =
840
 
                  gdk_pixbuf_new_from_file_at_size (icondir.c_str (), 40, 20,
841
 
                                                    NULL);
842
 
                if (pix)
843
 
                  {
844
 
                    gtk_tree_store_set (mStore, mitr, 0, node, 1, pix, 2,
845
 
                                        name, -1);
846
 
                    g_object_unref (pix);
847
 
                  }
848
 
                else
849
 
                  {
850
 
                    gtk_tree_store_set (mStore, mitr, 0, node, 2, name, -1);
851
 
                  }
852
 
 
853
 
                if (!walk_dir_path_index (mitr, realname))
854
 
                  {
855
 
                    gtk_tree_store_remove (mStore, mitr);
856
 
                    delete node;
857
 
                    node = NULL;
858
 
                  }
859
 
 
860
 
                if (node != NULL)
861
 
                  {
862
 
                    mDirNodes = g_list_append (mDirNodes, node);
863
 
                    has = true;
864
 
                  }
865
 
              }
866
 
            else if (g_ascii_strncasecmp (name + strlen (name) - 4, ".pdf", 4)
867
 
                     == 0
868
 
                     || g_ascii_strncasecmp (name + strlen (name) - 5,
869
 
                                             ".djvu", 5) == 0
870
 
                     || g_ascii_strncasecmp (name + strlen (name) - 4, ".djv",
871
 
                                             4) == 0)
872
 
              {
873
 
                GtkTreeIter mitr[1];
874
 
                gtk_tree_store_append (mStore, mitr, itr);
875
 
                node = new ApvlvDirNode (mitr, false, realname, name);
876
 
                mDirNodes = g_list_append (mDirNodes, node);
877
 
 
878
 
                GdkPixbuf *pix =
879
 
                  gdk_pixbuf_new_from_file_at_size (iconpdf.c_str (), 40, 20,
880
 
                                                    NULL);
881
 
                if (pix)
882
 
                  {
883
 
                    gtk_tree_store_set (mStore, mitr, 0, node, 1, pix, 2,
884
 
                                        name, -1);
885
 
                    g_object_unref (pix);
886
 
                  }
887
 
                else
888
 
                  {
889
 
                    gtk_tree_store_set (mStore, mitr, 0, node, 2, name, -1);
890
 
                  }
891
 
 
892
 
                has = true;
893
 
              }
894
 
 
895
 
            g_free (realname);
896
 
          }
 
810
            ApvlvDirNode *node = NULL;
 
811
            struct stat buf[1];
 
812
            char *wrealname =
 
813
              g_locale_from_utf8 (realname, -1, NULL, NULL, NULL);
 
814
            if (wrealname == NULL)
 
815
              {
 
816
                g_free (realname);
 
817
                continue;
 
818
              }
 
819
 
 
820
            int ret = stat (wrealname, buf);
 
821
            g_free (wrealname);
 
822
 
 
823
            if (ret < 0)
 
824
              {
 
825
                g_free (realname);
 
826
                continue;
 
827
              }
 
828
 
 
829
            if (S_ISDIR (buf->st_mode))
 
830
              {
 
831
                GtkTreeIter mitr[1];
 
832
                gtk_tree_store_append (mStore, mitr, itr);
 
833
                node = new ApvlvDirNode (mitr, true, realname, name);
 
834
 
 
835
                GdkPixbuf *pix =
 
836
                  gdk_pixbuf_new_from_file_at_size (icondir.c_str (), 40, 20,
 
837
                                                    NULL);
 
838
                if (pix)
 
839
                  {
 
840
                    gtk_tree_store_set (mStore, mitr, 0, node, 1, pix, 2,
 
841
                                        name, -1);
 
842
                    g_object_unref (pix);
 
843
                  }
 
844
                else
 
845
                  {
 
846
                    gtk_tree_store_set (mStore, mitr, 0, node, 2, name, -1);
 
847
                  }
 
848
 
 
849
                if (!walk_dir_path_index (mitr, realname))
 
850
                  {
 
851
                    gtk_tree_store_remove (mStore, mitr);
 
852
                    delete node;
 
853
                    node = NULL;
 
854
                  }
 
855
 
 
856
                if (node != NULL)
 
857
                  {
 
858
                    mDirNodes = g_list_append (mDirNodes, node);
 
859
                    has = true;
 
860
                  }
 
861
              }
 
862
            else if (g_ascii_strncasecmp (name + strlen (name) - 4, ".pdf", 4)
 
863
                     == 0
 
864
#ifdef HAVE_LIBUMD
 
865
                     || g_ascii_strncasecmp (name + strlen (name) - 5,
 
866
                                             ".djvu", 5) == 0
 
867
                     || g_ascii_strncasecmp (name + strlen (name) - 4, ".djv",
 
868
                                             4) == 0
 
869
#endif
 
870
#ifdef HAVE_LIBUMD
 
871
                     || g_ascii_strncasecmp (name + strlen (name) - 4,
 
872
                                             ".umd", 4) == 0
 
873
#endif
 
874
                    )
 
875
              {
 
876
                GtkTreeIter mitr[1];
 
877
                gtk_tree_store_append (mStore, mitr, itr);
 
878
                node = new ApvlvDirNode (mitr, false, realname, name);
 
879
                mDirNodes = g_list_append (mDirNodes, node);
 
880
 
 
881
                GdkPixbuf *pix =
 
882
                  gdk_pixbuf_new_from_file_at_size (iconpdf.c_str (), 40, 20,
 
883
                                                    NULL);
 
884
                if (pix)
 
885
                  {
 
886
                    gtk_tree_store_set (mStore, mitr, 0, node, 1, pix, 2,
 
887
                                        name, -1);
 
888
                    g_object_unref (pix);
 
889
                  }
 
890
                else
 
891
                  {
 
892
                    gtk_tree_store_set (mStore, mitr, 0, node, 2, name, -1);
 
893
                  }
 
894
 
 
895
                has = true;
 
896
              }
 
897
 
 
898
            g_free (realname);
 
899
          }
897
900
      }
898
901
    g_dir_close (dir);
899
902