File: pkg.cc

package info (click to toggle)
paco 2.0.9-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,136 kB
  • sloc: sh: 10,464; cpp: 6,463; ansic: 338; makefile: 277; perl: 260
file content (121 lines) | stat: -rw-r--r-- 2,413 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//=======================================================================
// pkg.cc
//-----------------------------------------------------------------------
// This file is part of the package paco
// Copyright (C) 2004-2009 David Rosal
// For more information visit http://paco.sourceforge.net
//=======================================================================

#include "config.h"
#include "pkg.h"
#include "pkgwindow.h"
#include "filestreeview.h"
#include "filestab.h"
#include "paco/file.h"
#include <gdkmm/pixbuf.h>
#include <fstream>

using Glib::ustring;
using std::string;
using namespace Gpaco;


Pkg::Pkg(ustring const& __name)
:
	Paco::BasePkg(__name),
	mSizePercent(0),
	mFilesPercent(0),
	mpIcon(),
	mSummary(),
	mpWindow(NULL),
	mFileType(Pkg::INSTALLED_FILES),
	mChanged(false)
{
	readLog();
}


// [virtual]
Pkg::~Pkg()
{ }


void Pkg::readLog()
{
	string buf;
	std::ifstream f(mLog.c_str());
	g_return_if_fail(f);
	
	while (getline(f, buf) && buf[0] == '#') {
		if (!buf.find("##:")) {
			sscanf(buf.c_str(), "##:%ld|%ld|%ld|%ld",
				&mSizeInst, &mSizeMiss, &mFilesInst, &mFilesMiss);
		}
		else if (!buf.find("#i:/"))
			getIcon(buf.substr(3));
		else if (!buf.find("#:Summary: ")) {
			mSummary = buf.substr(11);
			break;
		}
	}

	f.close();
	getFiles();

	long total = mSizeInst + mSizeMiss;
	mSizePercent = total ? (100.0 * mSizeInst / total) : 100.0;
	total = mFilesInst + mFilesMiss;
	mFilesPercent = total ? (100.0 * mFilesInst / total) : 0.0;
}


void Pkg::getIcon(ustring const& path)
try {
	if (Glib::RefPtr<Gdk::Pixbuf> p = Gdk::Pixbuf::create_from_file(path)) {
		if (p->get_width() >= 72 || p->get_height() >= 72)
			mpIcon = p->scale_simple(72, 72, Gdk::INTERP_BILINEAR);
		else if (p->get_width() <= 24 || p->get_height() <= 24)
			mpIcon = p->scale_simple(24, 24, Gdk::INTERP_BILINEAR);
		else
			mpIcon = p;
	}
} catch (...) { }


void Pkg::presentWindow(int tab)
{
	if (!mpWindow) {
		mpWindow = new PkgWindow(*this);
		mpWindow->filesTab()->treeView()->writeLabel();
	}
	mpWindow->presentTab(tab);
}


void Pkg::deleteWindow()
{
	if (mpWindow) {
		delete mpWindow;
		mpWindow = NULL;
	}
}


bool Pkg::update(bool resetFilesModel /* = true */)
{
	bool ret = true;
	
	try {
		if ((ret = updateLog(mLog))) {
			readLog();
			if (mpWindow && resetFilesModel)
				mpWindow->filesTab()->treeView()->resetModel();
		}
	}
	catch (...) { }

	mChanged = true;

	return ret;
}