-rw-r--r-- | noncore/settings/aqpkg/utils.cpp | 24 | ||||
-rw-r--r-- | noncore/settings/aqpkg/utils.h | 1 |
2 files changed, 24 insertions, 1 deletions
diff --git a/noncore/settings/aqpkg/utils.cpp b/noncore/settings/aqpkg/utils.cpp index 77d82d4..446ce39 100644 --- a/noncore/settings/aqpkg/utils.cpp +++ b/noncore/settings/aqpkg/utils.cpp | |||
@@ -1,74 +1,96 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | utils.cpp - description | 2 | utils.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Sat Sep 7 2002 | 4 | begin : Sat Sep 7 2002 |
5 | copyright : (C) 2002 by Andy Qua | 5 | copyright : (C) 2002 by Andy Qua |
6 | email : andy.qua@blueyonder.co.uk | 6 | email : andy.qua@blueyonder.co.uk |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include <stdio.h> | ||
19 | #include <sys/vfs.h> | ||
20 | //#include <mntent.h> | ||
21 | |||
18 | #include "utils.h" | 22 | #include "utils.h" |
19 | #include "global.h" | 23 | #include "global.h" |
20 | 24 | ||
21 | Utils :: Utils() | 25 | Utils :: Utils() |
22 | { | 26 | { |
23 | } | 27 | } |
24 | 28 | ||
25 | Utils :: ~Utils() | 29 | Utils :: ~Utils() |
26 | { | 30 | { |
27 | } | 31 | } |
28 | 32 | ||
29 | 33 | ||
30 | QString Utils :: getPathfromIpkFilename( const QString &file ) | 34 | QString Utils :: getPathfromIpkFilename( const QString &file ) |
31 | { | 35 | { |
32 | int p = file.findRev( "/" ); | 36 | int p = file.findRev( "/" ); |
33 | QString path = ""; | 37 | QString path = ""; |
34 | if ( p != -1 ) | 38 | if ( p != -1 ) |
35 | path = file.left( p ); | 39 | path = file.left( p ); |
36 | 40 | ||
37 | return path; | 41 | return path; |
38 | 42 | ||
39 | } | 43 | } |
40 | 44 | ||
41 | QString Utils :: getFilenameFromIpkFilename( const QString &file ) | 45 | QString Utils :: getFilenameFromIpkFilename( const QString &file ) |
42 | { | 46 | { |
43 | int p = file.findRev( "/" ); | 47 | int p = file.findRev( "/" ); |
44 | QString name = file; | 48 | QString name = file; |
45 | if ( p != -1 ) | 49 | if ( p != -1 ) |
46 | name = name.mid( p + 1 ); | 50 | name = name.mid( p + 1 ); |
47 | 51 | ||
48 | 52 | ||
49 | return name; | 53 | return name; |
50 | } | 54 | } |
51 | 55 | ||
52 | QString Utils :: getPackageNameFromIpkFilename( const QString &file ) | 56 | QString Utils :: getPackageNameFromIpkFilename( const QString &file ) |
53 | { | 57 | { |
54 | int p = file.findRev( "/" ); | 58 | int p = file.findRev( "/" ); |
55 | QString name = file; | 59 | QString name = file; |
56 | if ( p != -1 ) | 60 | if ( p != -1 ) |
57 | name = name.mid( p + 1 ); | 61 | name = name.mid( p + 1 ); |
58 | p = name.find( "_" ); | 62 | p = name.find( "_" ); |
59 | QString packageName = name.mid( 0, p ); | 63 | QString packageName = name.mid( 0, p ); |
60 | return packageName; | 64 | return packageName; |
61 | } | 65 | } |
62 | 66 | ||
63 | QString Utils :: getPackageVersionFromIpkFilename( const QString &file ) | 67 | QString Utils :: getPackageVersionFromIpkFilename( const QString &file ) |
64 | { | 68 | { |
65 | int p = file.findRev( "/" ); | 69 | int p = file.findRev( "/" ); |
66 | QString name = file; | 70 | QString name = file; |
67 | if ( p != -1 ) | 71 | if ( p != -1 ) |
68 | name = name.mid( p + 1 ); | 72 | name = name.mid( p + 1 ); |
69 | p = name.find( "_" ) + 1; | 73 | p = name.find( "_" ) + 1; |
70 | int p2 = name.find( "_", p ); | 74 | int p2 = name.find( "_", p ); |
71 | QString version = name.mid( p, p2 - p ); | 75 | QString version = name.mid( p, p2 - p ); |
72 | return version; | 76 | return version; |
73 | } | 77 | } |
74 | 78 | ||
79 | |||
80 | bool Utils :: getStorageSpace( const char *path, long *blockSize, long *totalBlocks, long *availBlocks ) | ||
81 | { | ||
82 | bool ret = false; | ||
83 | |||
84 | // qDebug( "Reading from path %s", path ); | ||
85 | struct statfs fs; | ||
86 | if ( !statfs( path, &fs ) ) | ||
87 | { | ||
88 | *blockSize = fs.f_bsize; | ||
89 | *totalBlocks = fs.f_blocks; | ||
90 | *availBlocks = fs.f_bavail; | ||
91 | ret = true; | ||
92 | } | ||
93 | |||
94 | return ret; | ||
95 | } | ||
96 | |||
diff --git a/noncore/settings/aqpkg/utils.h b/noncore/settings/aqpkg/utils.h index 15ee4e6..c572f7b 100644 --- a/noncore/settings/aqpkg/utils.h +++ b/noncore/settings/aqpkg/utils.h | |||
@@ -1,38 +1,39 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | utils.h - description | 2 | utils.h - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Sat Sep 7 2002 | 4 | begin : Sat Sep 7 2002 |
5 | copyright : (C) 2002 by Andy Qua | 5 | copyright : (C) 2002 by Andy Qua |
6 | email : andy.qua@blueyonder.co.uk | 6 | email : andy.qua@blueyonder.co.uk |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #ifndef UTILS_H | 18 | #ifndef UTILS_H |
19 | #define UTILS_H | 19 | #define UTILS_H |
20 | 20 | ||
21 | #include <qstring.h> | 21 | #include <qstring.h> |
22 | 22 | ||
23 | /** | 23 | /** |
24 | *@author Andy Qua | 24 | *@author Andy Qua |
25 | */ | 25 | */ |
26 | 26 | ||
27 | class Utils { | 27 | class Utils { |
28 | public: | 28 | public: |
29 | Utils(); | 29 | Utils(); |
30 | ~Utils(); | 30 | ~Utils(); |
31 | 31 | ||
32 | static QString getPathfromIpkFilename( const QString &file ); | 32 | static QString getPathfromIpkFilename( const QString &file ); |
33 | static QString getFilenameFromIpkFilename( const QString &file ); | 33 | static QString getFilenameFromIpkFilename( const QString &file ); |
34 | static QString getPackageNameFromIpkFilename( const QString &file ); | 34 | static QString getPackageNameFromIpkFilename( const QString &file ); |
35 | static QString getPackageVersionFromIpkFilename( const QString &file ); | 35 | static QString getPackageVersionFromIpkFilename( const QString &file ); |
36 | static bool getStorageSpace( const char *path, long *blockSize, long *totalBlocks, long *availBlocks ); | ||
36 | }; | 37 | }; |
37 | 38 | ||
38 | #endif | 39 | #endif |