~ubuntu-branches/ubuntu/quantal/recoll/quantal

« back to all changes in this revision

Viewing changes to utils/pathut.cpp

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2012-03-27 12:15:51 UTC
  • mfrom: (1.3.8)
  • Revision ID: package-import@ubuntu.com-20120327121551-nmntidzpehudushy
Tags: 1.17.1-1
* New upstream release.
* Enable Python module resulting into new binary: python-recoll.
* debian/control:
  + Updated Build-Deps: libqtwebkit-dev, python-all-dev.
  + Added python-recoll binary.
  + Updated Standards-Version to 3.9.3
* debian/rules:
  + Build Python module by default.
* debian/recoll.menu, debian/python-recoll.install, debian/recoll.install:
  + Changes for new binary package.
* debian/copyright:
  + Updated to copyright-format 1.0
  + Updated upstream and Debian copyright.
  + Fixed unicode.org/copyright.html URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
#include "pathut.h"
59
59
#include "transcode.h"
60
60
#include "wipedir.h"
 
61
#include "md5.h"
61
62
 
62
63
bool fsocc(const string &path, int *pc, long *blocks)
63
64
{
559
560
    return unlink(m_path.c_str());
560
561
}
561
562
 
 
563
// Freedesktop standard paths for thumbnails
 
564
 
 
565
// Place for 256x256 files
 
566
static const string thmbdirlarge = ".thumbnails/large";
 
567
// 128x128
 
568
static const string thmbdirnormal = ".thumbnails/normal";
 
569
 
 
570
static void thumbname(const string& url, string& name)
 
571
{
 
572
    string digest;
 
573
    MD5String(url, digest);
 
574
    MD5HexPrint(digest, name);
 
575
    name += ".png";
 
576
}
 
577
 
 
578
bool thumbPathForUrl(const string& url, int size, string& path)
 
579
{
 
580
    string name;
 
581
    thumbname(url, name);
 
582
    if (size <= 128) {
 
583
        path = path_cat(path_home(), thmbdirnormal);
 
584
        path = path_cat(path, name);
 
585
        if (access(path.c_str(), R_OK) == 0) {
 
586
            return true;
 
587
        }
 
588
    } 
 
589
    path = path_cat(path_home(), thmbdirlarge);
 
590
    path = path_cat(path, name);
 
591
    if (access(path.c_str(), R_OK) == 0) {
 
592
        return true;
 
593
    }
 
594
 
 
595
    // File does not exist. Path corresponds to the large version at this point,
 
596
    // fix it if needed.
 
597
    if (size <= 128) {
 
598
        path = path_cat(path_home(), thmbdirnormal);
 
599
        path = path_cat(path, name);
 
600
    }
 
601
    return false;
 
602
}
 
603
 
562
604
#else // TEST_PATHUT
563
605
#include <stdlib.h>
564
606
#include <iostream>
645
687
  printf("pc %d, megabytes %ld\n", pc, blocks);
646
688
#endif
647
689
 
648
 
#if 1
 
690
#if 0
649
691
  Pidfile pidfile("/tmp/pathutpidfile");
650
692
  pid_t pid;
651
693
  if ((pid = pidfile.open()) != 0) {
659
701
  pidfile.remove();
660
702
#endif
661
703
 
 
704
#if 1
 
705
  if (argc != 2) {
 
706
      fprintf(stderr, "Usage: thumbpath <filepath> <size>\n");
 
707
      exit(1);
 
708
  }
 
709
 
 
710
  string input = *argv++;
 
711
  int size = atoi(*argv++);
 
712
 
 
713
  if (input.empty())  {
 
714
      fprintf(stderr, "Usage: thumbpath <filepath> <size>\n");
 
715
      exit(1);
 
716
  }
 
717
 
 
718
  // Make absolute path if needed
 
719
  if (input[0] != '/') {
 
720
      input = path_absolute(input);
 
721
  }
 
722
  input = string("file://") + path_canon(input);
 
723
  string path;
 
724
  if (thumbPathForUrl(input, size, path)) {
 
725
      cout << "Thumbnail for [" << input << "] [" << path << "]" << endl;
 
726
  } else {
 
727
      cout << "No thumbnail for [" << input << "] path [" << path << "]" <<endl;
 
728
  }
 
729
  
 
730
  exit(0);
 
731
#endif
 
732
 
662
733
    return 0;
663
734
}
664
735