summaryrefslogtreecommitdiff
path: root/library
authorzecke <zecke>2002-05-16 15:56:24 (UTC)
committer zecke <zecke>2002-05-16 15:56:24 (UTC)
commitb94bd6003bf7c2024b0f254805f54ff4e52ead6e (patch) (unidiff)
tree8e137366438872bbd2ca03256678c9a2d10d7517 /library
parent0292492b1c9570a896ac4b9acfe168724e8439f9 (diff)
downloadopie-b94bd6003bf7c2024b0f254805f54ff4e52ead6e.zip
opie-b94bd6003bf7c2024b0f254805f54ff4e52ead6e.tar.gz
opie-b94bd6003bf7c2024b0f254805f54ff4e52ead6e.tar.bz2
Some ole docu and search for jpgs too in Resource PNG, JPG, XPM
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp14
-rw-r--r--library/resource.cpp8
2 files changed, 20 insertions, 2 deletions
diff --git a/library/global.cpp b/library/global.cpp
index 4f1cc38..edb7b85 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -595,118 +595,132 @@ void Global::execute( const QString &c, const QString& document )
595 qDebug("executing %s", ap.latin1() ); 595 qDebug("executing %s", ap.latin1() );
596 if ( ap == "suspend" ) { 596 if ( ap == "suspend" ) {
597 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 597 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
598 return; 598 return;
599 } 599 }
600 600
601 /* if need be, sending a qcop message will result in an invoke, see 601 /* if need be, sending a qcop message will result in an invoke, see
602 preceeding function */ 602 preceeding function */
603 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 603 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
604 if ( !document.isEmpty() ) { 604 if ( !document.isEmpty() ) {
605 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); 605 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" );
606 env << document; 606 env << document;
607 } 607 }
608#endif 608#endif
609} 609}
610 610
611/*! 611/*!
612 Returns the string \a s with the characters backslash, ", and $ 612 Returns the string \a s with the characters backslash, ", and $
613 quoted by a preceeding backslash. 613 quoted by a preceeding backslash.
614*/ 614*/
615QString Global::shellQuote(const QString& s) 615QString Global::shellQuote(const QString& s)
616{ 616{
617 QString r="\""; 617 QString r="\"";
618 for (int i=0; i<(int)s.length(); i++) { 618 for (int i=0; i<(int)s.length(); i++) {
619 char c = s[i].latin1(); 619 char c = s[i].latin1();
620 switch (c) { 620 switch (c) {
621 case '\\': case '"': case '$': 621 case '\\': case '"': case '$':
622 r+="\\"; 622 r+="\\";
623 } 623 }
624 r += s[i]; 624 r += s[i];
625 } 625 }
626 r += "\""; 626 r += "\"";
627 return r; 627 return r;
628} 628}
629 629
630/*! 630/*!
631 Returns the string \a s with the characters backslash and " 631 Returns the string \a s with the characters backslash and "
632 quoted by a preceeding backslash. 632 quoted by a preceeding backslash.
633*/ 633*/
634QString Global::stringQuote(const QString& s) 634QString Global::stringQuote(const QString& s)
635{ 635{
636 QString r="\""; 636 QString r="\"";
637 for (int i=0; i<(int)s.length(); i++) { 637 for (int i=0; i<(int)s.length(); i++) {
638 char c = s[i].latin1(); 638 char c = s[i].latin1();
639 switch (c) { 639 switch (c) {
640 case '\\': case '"': 640 case '\\': case '"':
641 r+="\\"; 641 r+="\\";
642 } 642 }
643 r += s[i]; 643 r += s[i];
644 } 644 }
645 r += "\""; 645 r += "\"";
646 return r; 646 return r;
647} 647}
648 648
649/*! 649/*!
650 Finds all documents on the system's document directories which 650 Finds all documents on the system's document directories which
651 match the filter \a mimefilter, and appends the resulting DocLnk 651 match the filter \a mimefilter, and appends the resulting DocLnk
652 objects to \a folder. 652 objects to \a folder.
653*/ 653*/
654void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) 654void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
655{ 655{
656 QString homedocs = QString(getenv("HOME")) + "/Documents"; 656 QString homedocs = QString(getenv("HOME")) + "/Documents";
657 DocLnkSet d(homedocs,mimefilter); 657 DocLnkSet d(homedocs,mimefilter);
658 folder->appendFrom(d); 658 folder->appendFrom(d);
659 /** let's do intellegint way of searching these files
660 * a) the user don't want to check mediums global
661 * b) the user wants to check but use the global options for it
662 * c) the user wants to check it but not this medium
663 * d) the user wants to check and this medium as well
664 *
665 * In all cases we need to apply a different mimefilter to
666 * the medium.
667 * a) mimefilter.isEmpty() we need to apply the responding filter
668 * either the global or the one on the medium
669 *
670 * b) mimefilter is set to an application we need to find out if the
671 * mimetypes are included in the mime mask of the medium
672 */
659 StorageInfo storage; 673 StorageInfo storage;
660 const QList<FileSystem> &fs = storage.fileSystems(); 674 const QList<FileSystem> &fs = storage.fileSystems();
661 QListIterator<FileSystem> it ( fs ); 675 QListIterator<FileSystem> it ( fs );
662 for ( ; it.current(); ++it ) { 676 for ( ; it.current(); ++it ) {
663 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 677 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
664 // this is a candidate look at the cf and see if we should search on it 678 // this is a candidate look at the cf and see if we should search on it
665 QString path = (*it)->path(); 679 QString path = (*it)->path();
666 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) 680 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) )
667 continue; 681 continue;
668 DocLnkSet ide( path, mimefilter ); 682 DocLnkSet ide( path, mimefilter );
669 folder->appendFrom(ide); 683 folder->appendFrom(ide);
670 } 684 }
671 } 685 }
672} 686}
673 687
674QStringList Global::languageList() 688QStringList Global::languageList()
675{ 689{
676 QString lang = getenv("LANG"); 690 QString lang = getenv("LANG");
677 QStringList langs; 691 QStringList langs;
678 langs.append(lang); 692 langs.append(lang);
679 int i = lang.find("."); 693 int i = lang.find(".");
680 if ( i > 0 ) 694 if ( i > 0 )
681 lang = lang.left( i ); 695 lang = lang.left( i );
682 i = lang.find( "_" ); 696 i = lang.find( "_" );
683 if ( i > 0 ) 697 if ( i > 0 )
684 langs.append(lang.left(i)); 698 langs.append(lang.left(i));
685 return langs; 699 return langs;
686} 700}
687 701
688QStringList Global::helpPath() 702QStringList Global::helpPath()
689{ 703{
690 QStringList path; 704 QStringList path;
691 QStringList langs = Global::languageList(); 705 QStringList langs = Global::languageList();
692 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { 706 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
693 QString lang = *it; 707 QString lang = *it;
694 if ( !lang.isEmpty() ) 708 if ( !lang.isEmpty() )
695 path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; 709 path += QPEApplication::qpeDir() + "/help/" + lang + "/html";
696 } 710 }
697 path += QPEApplication::qpeDir() + "/pics"; 711 path += QPEApplication::qpeDir() + "/pics";
698 path += QPEApplication::qpeDir() + "/help/en/html"; 712 path += QPEApplication::qpeDir() + "/help/en/html";
699 path += QPEApplication::qpeDir() + "/docs"; 713 path += QPEApplication::qpeDir() + "/docs";
700 QString dir = QDir::current().canonicalPath(); 714 QString dir = QDir::current().canonicalPath();
701 if ( dir == "/" ) 715 if ( dir == "/" )
702 dir += "/docs"; 716 dir += "/docs";
703 else { 717 else {
704 path += dir + "/../pics"; 718 path += dir + "/../pics";
705 dir += "/../docs"; 719 dir += "/../docs";
706 path += dir; 720 path += dir;
707 } 721 }
708 return path; 722 return path;
709} 723}
710 724
711 725
712#include "global.moc" 726#include "global.moc"
diff --git a/library/resource.cpp b/library/resource.cpp
index dc19880..0915c45 100644
--- a/library/resource.cpp
+++ b/library/resource.cpp
@@ -7,130 +7,134 @@
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qpeapplication.h" 21#include "qpeapplication.h"
22#include "resource.h" 22#include "resource.h"
23#include <qdir.h> 23#include <qdir.h>
24#include <qfile.h> 24#include <qfile.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qpixmapcache.h> 26#include <qpixmapcache.h>
27#include <qpainter.h> 27#include <qpainter.h>
28 28
29#include "inlinepics_p.h" 29#include "inlinepics_p.h"
30 30
31/*! 31/*!
32 \class Resource resource.h 32 \class Resource resource.h
33 \brief The Resource class provides access to named resources. 33 \brief The Resource class provides access to named resources.
34 34
35 The resources may be provided from files or other sources. 35 The resources may be provided from files or other sources.
36*/ 36*/
37 37
38/*! 38/*!
39 \fn Resource::Resource() 39 \fn Resource::Resource()
40 \internal 40 \internal
41*/ 41*/
42 42
43/*! 43/*!
44 Returns the QPixmap named \a pix. You should avoid including 44 Returns the QPixmap named \a pix. You should avoid including
45 any filename type extension (eg. .png, .xpm). 45 any filename type extension (eg. .png, .xpm).
46*/ 46*/
47QPixmap Resource::loadPixmap( const QString &pix ) 47QPixmap Resource::loadPixmap( const QString &pix )
48{ 48{
49 QPixmap pm; 49 QPixmap pm;
50 QString key="QPE_"+pix; 50 QString key="QPE_"+pix;
51 if ( !QPixmapCache::find(key,pm) ) { 51 if ( !QPixmapCache::find(key,pm) ) {
52 pm.convertFromImage(loadImage(pix)); 52 pm.convertFromImage(loadImage(pix));
53 QPixmapCache::insert(key,pm); 53 QPixmapCache::insert(key,pm);
54 } 54 }
55 return pm; 55 return pm;
56} 56}
57 57
58/*! 58/*!
59 Returns the QBitmap named \a pix. You should avoid including 59 Returns the QBitmap named \a pix. You should avoid including
60 any filename type extension (eg. .png, .xpm). 60 any filename type extension (eg. .png, .xpm).
61*/ 61*/
62QBitmap Resource::loadBitmap( const QString &pix ) 62QBitmap Resource::loadBitmap( const QString &pix )
63{ 63{
64 QBitmap bm; 64 QBitmap bm;
65 bm = loadPixmap(pix); 65 bm = loadPixmap(pix);
66 return bm; 66 return bm;
67} 67}
68 68
69/*! 69/*!
70 Returns the filename of a pixmap named \a pix. You should avoid including 70 Returns the filename of a pixmap named \a pix. You should avoid including
71 any filename type extension (eg. .png, .xpm). 71 any filename type extension (eg. .png, .xpm .jpg .jpeg).
72 72
73 Normally you will use loadPixmap() rather than this function. 73 Normally you will use loadPixmap() rather than this function.
74*/ 74*/
75QString Resource::findPixmap( const QString &pix ) 75QString Resource::findPixmap( const QString &pix )
76{ 76{
77 QString picsPath = QPEApplication::qpeDir() + "pics/"; 77 QString picsPath = QPEApplication::qpeDir() + "pics/";
78 78
79 if ( QFile( picsPath + pix + ".png").exists() ) 79 if ( QFile( picsPath + pix + ".png").exists() )
80 return picsPath + pix + ".png"; 80 return picsPath + pix + ".png";
81 else if ( QFile( picsPath + pix + ".jpeg").exists() )
82 return picsPath + pix + ".jpeg";
83 else if ( QFile( picsPath + pix + ".jpg").exists() )
84 return picsPath + pix + ".jpg";
81 else if ( QFile( picsPath + pix + ".xpm").exists() ) 85 else if ( QFile( picsPath + pix + ".xpm").exists() )
82 return picsPath + pix + ".xpm"; 86 return picsPath + pix + ".xpm";
83 else if ( QFile( picsPath + pix ).exists() ) 87 else if ( QFile( picsPath + pix ).exists() )
84 return picsPath + pix; 88 return picsPath + pix;
85 89
86 //qDebug("Cannot find pixmap: %s", pix.latin1()); 90 //qDebug("Cannot find pixmap: %s", pix.latin1());
87 return QString(); 91 return QString();
88} 92}
89 93
90/*! 94/*!
91 Returns a sound file for a sound named \a name. 95 Returns a sound file for a sound named \a name.
92 You should avoid including any filename type extension (eg. .wav, .au, .mp3). 96 You should avoid including any filename type extension (eg. .wav, .au, .mp3).
93*/ 97*/
94QString Resource::findSound( const QString &name ) 98QString Resource::findSound( const QString &name )
95{ 99{
96 QString picsPath = QPEApplication::qpeDir() + "sounds/"; 100 QString picsPath = QPEApplication::qpeDir() + "sounds/";
97 101
98 QString result; 102 QString result;
99 if ( QFile( (result = picsPath + name + ".wav") ).exists() ) 103 if ( QFile( (result = picsPath + name + ".wav") ).exists() )
100 return result; 104 return result;
101 105
102 return QString(); 106 return QString();
103} 107}
104 108
105/*! 109/*!
106 Returns a list of all sound names. 110 Returns a list of all sound names.
107*/ 111*/
108QStringList Resource::allSounds() 112QStringList Resource::allSounds()
109{ 113{
110 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); 114 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" );
111 QStringList entries = resourcedir.entryList(); 115 QStringList entries = resourcedir.entryList();
112 QStringList result; 116 QStringList result;
113 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) 117 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i)
114 result.append((*i).replace(QRegExp("\\.wav"),"")); 118 result.append((*i).replace(QRegExp("\\.wav"),""));
115 return result; 119 return result;
116} 120}
117 121
118/*! 122/*!
119 Returns the QImage named \a name. You should avoid including 123 Returns the QImage named \a name. You should avoid including
120 any filename type extension (eg. .png, .xpm). 124 any filename type extension (eg. .png, .xpm .jpg).
121*/ 125*/
122QImage Resource::loadImage( const QString &name) 126QImage Resource::loadImage( const QString &name)
123{ 127{
124 QImage img = qembed_findImage(name.latin1()); 128 QImage img = qembed_findImage(name.latin1());
125 if ( img.isNull() ) 129 if ( img.isNull() )
126 return QImage(findPixmap(name)); 130 return QImage(findPixmap(name));
127 return img; 131 return img;
128} 132}
129 133
130/*! 134/*!
131 \fn QIconSet Resource::loadIconSet( const QString &name ) 135 \fn QIconSet Resource::loadIconSet( const QString &name )
132 136
133 Returns a QIconSet for the pixmap named \a name. A disabled icon is 137 Returns a QIconSet for the pixmap named \a name. A disabled icon is
134 generated that conforms to the Qtopia look & feel. You should avoid 138 generated that conforms to the Qtopia look & feel. You should avoid
135 including any filename type extension (eg. .png, .xpm). 139 including any filename type extension (eg. .png, .xpm).
136*/ 140*/