~ubuntu-branches/ubuntu/lucid/kde4libs/lucid-updates

« back to all changes in this revision

Viewing changes to plasma/runnercontext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2010-02-04 14:24:15 UTC
  • mfrom: (1.1.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20100204142415-m9s99idmc0685wei
Tags: 4:4.4.0-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
    // path components
117
117
    QStringList components = QString(path).split(QDir::separator());
118
118
 
119
 
    if (components.size() < 2) {
 
119
    if (components.size() < 1) {
120
120
        return false;
121
121
    }
122
122
 
124
124
 
125
125
    //kDebug() << "Components are" << components;
126
126
 
 
127
    if (mustBeDir) {
 
128
        components.pop_back();
 
129
    }
 
130
 
127
131
    QString correctPath;
128
 
 
129
 
    if (components.back().isEmpty()) {
130
 
        components.pop_back();
131
 
    }
132
 
 
133
132
    const unsigned initialComponents = components.size();
134
133
    for (unsigned i = 0; i < initialComponents - 1; i ++) {
135
134
        const QString tmp = components[0] + QDir::separator() + components[1];
174
173
 
175
174
        /**
176
175
         * Determines type of query
 
176
                    &&
177
177
         */
178
178
        void determineType()
179
179
        {
191
191
                                     RunnerContext::Executable;
192
192
            } else {
193
193
                KUrl url(term);
194
 
                QString correctCasePath;
195
 
                // check if we have a local network location first, otherwise assume a path,
196
 
                // but if a path doesn't have any slashes is a single word or
197
 
                // sentence: it's too ambiguous to be sure we're in a filesystem context
198
 
                if (KProtocolInfo::protocolClass(url.protocol()) == ":local" && !url.isLocalFile()) {
 
194
                // check for a normal URL first
 
195
                //kDebug() << url << KProtocolInfo::protocolClass(url.protocol()) << url.hasHost() <<
 
196
                //    url.host() << url.isLocalFile() << path << path.indexOf('/');
 
197
                const bool hasProtocol = !url.protocol().isEmpty();
 
198
                const bool isLocalProtocol = KProtocolInfo::protocolClass(url.protocol()) == ":local";
 
199
                if (hasProtocol && 
 
200
                    ((!isLocalProtocol && url.hasHost()) ||
 
201
                     (isLocalProtocol && url.protocol() != "file"))) {
 
202
                    // we either have a network protocol with a host, so we can show matches for it
 
203
                    // or we have a non-file url that may be local so a host isn't required
199
204
                    type = RunnerContext::NetworkLocation;
200
 
                } else if ((path.indexOf('/') != -1 || path.indexOf('\\') != -1) &&
201
 
                           correctPathCase(path, correctCasePath)) {
202
 
                    path = correctCasePath;
203
 
                    QFileInfo info(path);
 
205
                } else if (isLocalProtocol) {
 
206
                    // at this point in the game, we assume we have a path,
 
207
                    // but if a path doesn't have any slashes
 
208
                    // it's too ambiguous to be sure we're in a filesystem context
 
209
                    path = QDir::cleanPath(url.toLocalFile());
 
210
                    //kDebug( )<< "slash check" << path;
 
211
                    if (hasProtocol || ((path.indexOf('/') != -1 || path.indexOf('\\') != -1))) {
 
212
                        QString correctCasePath;
 
213
                        if (correctPathCase(path, correctCasePath)) {
 
214
                            path = correctCasePath;
 
215
                            QFileInfo info(path);
 
216
                            //kDebug( )<< "correct cas epath is" << correctCasePath << info.isSymLink() <<
 
217
                            //    info.isDir() << info.isFile();
204
218
 
205
 
                    if (info.isSymLink()) {
206
 
                        path = info.canonicalFilePath();
207
 
                        info = QFileInfo(path);
208
 
                    }
209
 
                    if (info.isDir()) {
210
 
                        type = RunnerContext::Directory;
211
 
                        mimeType = "inode/folder";
212
 
                    } else if (info.isFile()) {
213
 
                        type = RunnerContext::File;
214
 
                        KMimeType::Ptr mimeTypePtr = KMimeType::findByPath(path);
215
 
                        if (mimeTypePtr) {
216
 
                            mimeType = mimeTypePtr->name();
 
219
                            if (info.isSymLink()) {
 
220
                                path = info.canonicalFilePath();
 
221
                                info = QFileInfo(path);
 
222
                            }
 
223
                            if (info.isDir()) {
 
224
                                type = RunnerContext::Directory;
 
225
                                mimeType = "inode/folder";
 
226
                            } else if (info.isFile()) {
 
227
                                type = RunnerContext::File;
 
228
                                KMimeType::Ptr mimeTypePtr = KMimeType::findByPath(path);
 
229
                                if (mimeTypePtr) {
 
230
                                    mimeType = mimeTypePtr->name();
 
231
                                }
 
232
                            }
217
233
                        }
218
234
                    }
219
235
                }
220
236
            }
 
237
 
 
238
            //kDebug() << "term2type" << term << type;
221
239
        }
222
240
 
223
241
        void invalidate()