PCManFM-Qt
filelauncher.h
1 /*
2  <one line to give the library's name and an idea of what it does.>
3  Copyright (C) 2012 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 
21 #ifndef FM_FILELAUNCHER_H
22 #define FM_FILELAUNCHER_H
23 
24 #include "libfmqtglobals.h"
25 #include <QWidget>
26 #include <libfm/fm.h>
27 
28 namespace Fm {
29 
30 class LIBFM_QT_API FileLauncher {
31 public:
32  FileLauncher();
33  virtual ~FileLauncher();
34 
35  bool launchFiles(QWidget* parent, FmFileInfoList* file_infos) {
36  GList* fileList = fm_file_info_list_peek_head_link(file_infos);
37  return launchFiles(parent, fileList);
38  }
39  bool launchPaths(QWidget* parent, FmPathList* paths) {
40  GList* pathList = fm_path_list_peek_head_link(paths);
41  return launchPaths(parent, pathList);
42  }
43 
44  bool launchFiles(QWidget* parent, GList* file_infos);
45  bool launchPaths(QWidget* parent, GList* paths);
46 
47  bool quickExec() const {
48  return quickExec_;
49  }
50 
51  void setQuickExec(bool value) {
52  quickExec_ = value;
53  }
54 
55 protected:
56 
57  virtual GAppInfo* getApp(GList* file_infos, FmMimeType* mime_type, GError** err);
58  virtual bool openFolder(GAppLaunchContext* ctx, GList* folder_infos, GError** err);
59  virtual FmFileLauncherExecAction execFile(FmFileInfo* file);
60  virtual bool error(GAppLaunchContext* ctx, GError* err, FmPath* path);
61  virtual int ask(const char* msg, char* const* btn_labels, int default_btn);
62 
63 private:
64  static GAppInfo* _getApp(GList* file_infos, FmMimeType* mime_type, gpointer user_data, GError** err) {
65  return reinterpret_cast<FileLauncher*>(user_data)->getApp(file_infos, mime_type, err);
66  }
67  static gboolean _openFolder(GAppLaunchContext* ctx, GList* folder_infos, gpointer user_data, GError** err) {
68  return reinterpret_cast<FileLauncher*>(user_data)->openFolder(ctx, folder_infos, err);
69  }
70  static FmFileLauncherExecAction _execFile(FmFileInfo* file, gpointer user_data) {
71  return reinterpret_cast<FileLauncher*>(user_data)->execFile(file);
72  }
73  static gboolean _error(GAppLaunchContext* ctx, GError* err, FmPath* file, gpointer user_data) {
74  return reinterpret_cast<FileLauncher*>(user_data)->error(ctx, err, file);
75  }
76  static int _ask(const char* msg, char* const* btn_labels, int default_btn, gpointer user_data) {
77  return reinterpret_cast<FileLauncher*>(user_data)->ask(msg, btn_labels, default_btn);
78  }
79 
80 private:
81  static FmFileLauncher funcs;
82  bool quickExec_; // Don't ask options on launch executable file
83 };
84 
85 }
86 
87 #endif // FM_FILELAUNCHER_H
Definition: appchoosercombobox.cpp:26
Definition: filelauncher.h:30