~ubuntu-branches/ubuntu/maverick/apvlv/maverick

« back to all changes in this revision

Viewing changes to src/ApvlvDoc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ritter
  • Date: 2010-04-07 11:13:08 UTC
  • mfrom: (1.3.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100407111308-6yozdlrcyv6bs5aq
Tags: 0.0.9.5-1
New upstream release (Closes: #576081, #576082)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include "ApvlvUtil.hpp"
30
30
#include "ApvlvParams.hpp"
 
31
#include "ApvlvInfo.hpp"
31
32
#include "ApvlvView.hpp"
32
33
#include "ApvlvDoc.hpp"
33
34
 
124
125
    if (mCurrentCache2)
125
126
      delete mCurrentCache2;
126
127
 
127
 
    savelastposition ();
 
128
    savelastposition (filename ());
128
129
    mPositions.clear ();
129
130
 
130
131
    delete mStatus;
694
695
      }
695
696
  }
696
697
 
697
 
  bool ApvlvDoc::savelastposition ()
 
698
  bool ApvlvDoc::savelastposition (const char *filename)
698
699
  {
699
 
    if (filename () == NULL
700
 
        || helppdf == filename () || gParams->valueb ("noinfo"))
 
700
    if (filename == NULL || helppdf == filename || gParams->valueb ("noinfo"))
701
701
      {
702
702
        return false;
703
703
      }
704
704
 
705
 
    gchar *path = absolutepath (sessionfile.c_str ());
706
 
    ofstream os (path, ios::app);
707
 
    g_free (path);
 
705
    bool ret = gInfo->file (mPagenum, scrollrate (), filename);
708
706
 
709
 
    if (os.is_open ())
710
 
      {
711
 
        os << ">";
712
 
        os << filename () << "\t";
713
 
        os << mPagenum << "\t";
714
 
        os << scrollrate ();
715
 
        os << "\n";
716
 
        os.close ();
717
 
        return true;
718
 
      }
719
 
    return false;
 
707
    return ret;
720
708
  }
721
709
 
722
 
  bool ApvlvDoc::loadlastposition ()
 
710
  bool ApvlvDoc::loadlastposition (const char *filename)
723
711
  {
724
 
    bool ret = false;
725
 
    int pagen = 0;
726
 
    double scrollr = 0.00;
 
712
    if (filename == NULL || helppdf == filename || gParams->valueb ("noinfo"))
 
713
      {
 
714
        showpage (0);
 
715
        return false;
 
716
      }
727
717
 
728
718
    if (gParams->valueb ("noinfo"))
729
719
      {
731
721
        return false;
732
722
      }
733
723
 
734
 
    char *path = absolutepath (sessionfile.c_str ());
735
 
    ifstream os (path, ios::in);
736
 
    g_free (path);
737
 
 
738
 
    if (os.is_open ())
739
 
      {
740
 
        string line;
741
 
 
742
 
        while ((getline (os, line)) != NULL)
743
 
          {
744
 
            const char *p = line.c_str ();
745
 
 
746
 
            if (*p == '>')
747
 
              {
748
 
                stringstream ss (++p);
749
 
 
750
 
                string files;
751
 
                ss >> files;
752
 
 
753
 
                if (files == mFilestr)
754
 
                  {
755
 
                    ss >> pagen >> scrollr;
756
 
                    ret = true;
757
 
                  }
758
 
              }
759
 
          }
760
 
        os.close ();
761
 
      }
 
724
    bool ret = false;
 
725
 
 
726
    infofile *fp = gInfo->file (filename);
 
727
 
762
728
 
763
729
    // correctly check
764
 
    mScrollvalue = scrollr >= 0 ? scrollr : 0;
765
 
    showpage (pagen >= 0 ? pagen : 0);
 
730
    mScrollvalue = fp->rate;
 
731
    showpage (fp->page);
766
732
 
767
733
    // Warning
768
734
    // I can't think a better way to scroll correctly when
774
740
 
775
741
  bool ApvlvDoc::reload ()
776
742
  {
777
 
    savelastposition ();
 
743
    savelastposition (filename ());
778
744
    return loadfile (mFilestr, false);
779
745
  }
780
746
 
783
749
    return loadfile (filename.c_str (), check);
784
750
  }
785
751
 
 
752
  gint ApvlvDoc::pagenumber ()
 
753
  {
 
754
    if (mContinuous && mCurrentCache2 != NULL)
 
755
      {
 
756
        if (scrollrate () > 0.5)
 
757
          {
 
758
            return mCurrentCache2->getpagenum () + 1;
 
759
          }
 
760
        else
 
761
          {
 
762
            return mCurrentCache1->getpagenum () + 1;
 
763
          }
 
764
      }
 
765
    else
 
766
      {
 
767
        return mPagenum + 1;
 
768
      }
 
769
  }
 
770
 
786
771
  bool ApvlvDoc::usecache ()
787
772
  {
788
773
    return false;
845
830
            mCurrentCache2 = new ApvlvDocCache (mFile);
846
831
          }
847
832
 
848
 
        loadlastposition ();
 
833
        loadlastposition (filename);
849
834
 
850
835
        mStatus->show ();
851
836
 
1988
1973
 
1989
1974
  void ApvlvDocStatus::active (bool act)
1990
1975
  {
1991
 
    GdkColor c;
1992
 
 
1993
 
    if (act)
1994
 
      {
1995
 
        c.red = 300;
1996
 
        c.green = 300;
1997
 
        c.blue = 300;
1998
 
      }
1999
 
    else
2000
 
      {
2001
 
        c.red = 30000;
2002
 
        c.green = 30000;
2003
 
        c.blue = 30000;
2004
 
      }
2005
 
 
2006
1976
    for (unsigned int i = 0; i < AD_STATUS_SIZE; ++i)
2007
1977
      {
2008
 
        gtk_widget_modify_fg (mStlab[i], GTK_STATE_NORMAL, &c);
 
1978
        gtk_widget_modify_fg (mStlab[i],
 
1979
                              (act) ? GTK_STATE_ACTIVE :
 
1980
                              GTK_STATE_INSENSITIVE, NULL);
2009
1981
      }
2010
1982
  }
2011
1983
 
2028
2000
      {
2029
2001
        gint pn = mDoc->pagenumber ();
2030
2002
 
2031
 
        if (mDoc->continuous () && mDoc->scrollrate () > 0.5)
2032
 
          {
2033
 
            pn++;
2034
 
          }
2035
 
 
2036
2003
        char temp[AD_STATUS_SIZE][256];
2037
2004
        gchar *bn;
2038
2005
        bn = g_path_get_basename (mDoc->filename ());