Importing EDE2 code to svn... NOTE: It doesn't compile! Stuff thats broken: edewm, eworkpanel, eiconman,

emenueditor
This commit is contained in:
Vedran Ljubovic
2006-08-20 18:43:09 +00:00
commit 65018f75b7
1004 changed files with 88271 additions and 0 deletions

364
efiler/EDE_FileBrowser.cxx Normal file
View File

@ -0,0 +1,364 @@
//
// "$Id: FileBrowser.cxx 5071 2006-05-02 21:57:08Z fabien $"
//
// FileBrowser routines.
//
// Copyright 1999-2006 by Michael Sweet.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
// Contents:
//
// FileBrowser::full_height() - Return the height of the list.
// FileBrowser::item_height() - Return the height of a list item.
// FileBrowser::item_width() - Return the width of a list item.
// FileBrowser::item_draw() - Draw a list item.
// FileBrowser::FileBrowser() - Create a FileBrowser widget.
// FileBrowser::load() - Load a directory into the browser.
// FileBrowser::filter() - Set the filename filter.
//
//
// Include necessary header files...
//
#include <fltk/FileBrowser.h>
#include <fltk/Browser.h>
#include <fltk/Item.h>
#include <fltk/draw.h>
#include <fltk/Color.h>
#include <fltk/Flags.h>
#include <fltk/Font.h>
#include <fltk/string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __CYGWIN__
# include <mntent.h>
#elif defined(WIN32)
# include <windows.h>
# include <direct.h>
// Apparently Borland C++ defines DIRECTORY in <direct.h>, which
// interfers with the FileIcon enumeration of the same name.
# ifdef DIRECTORY
# undef DIRECTORY
# endif // DIRECTORY
#endif // __CYGWIN__
#ifdef __EMX__
# define INCL_DOS
# define INCL_DOSMISC
# include <os2.h>
#endif // __EMX__
// CodeWarrior (__MWERKS__) gets its include paths confused, so we
// temporarily disable this...
#if defined(__APPLE__) && !defined(__MWERKS__)
# include <sys/param.h>
# include <sys/ucred.h>
# include <sys/mount.h>
#endif // __APPLE__ && !__MWERKS__
using namespace fltk;
//
// 'FileBrowser::FileBrowser()' - Create a FileBrowser widget.
//
FileBrowser::FileBrowser(int X, // I - Upper-lefthand X coordinate
int Y, // I - Upper-lefthand Y coordinate
int W, // I - Width in pixels
int H, // I - Height in pixels
const char *l) // I - Label text
: Browser(X, Y, W, H, l) {
// Initialize the filter pattern, current directory, and icon size...
pattern_ = "*";
directory_ = "";
icon_size_ = -1.0f;
filetype_ = FILES;
show_hidden_ = false;
}
//
// 'FileBrowser::load()' - Load a directory into the browser.
//
int // O - Number of files loaded
FileBrowser::load(const char *directory,// I - Directory to load
File_Sort_F *sort) // I - Sort function to use
{
int i; // Looping var
int num_files; // Number of files in directory
int num_dirs; // Number of directories in list
char filename[4096]; // Current file
FileIcon *icon; // Icon to use
// printf("FileBrowser::load(\"%s\")\n", directory);
if (!directory)
return (0);
clear();
directory_ = directory;
if (directory_[0] == '\0')
{
//
// No directory specified; for UNIX list all mount points. For DOS
// list all valid drive letters...
//
num_files = 0;
if ((icon = FileIcon::find("any", FileIcon::DEVICE)) == NULL)
icon = FileIcon::find("any", FileIcon::DIRECTORY);
#ifdef WIN32
# ifdef __CYGWIN__
//
// Cygwin provides an implementation of setmntent() to get the list
// of available drives...
//
FILE *m = setmntent("/-not-used-", "r");
struct mntent *p;
while ((p = getmntent (m)) != NULL) {
add(p->mnt_dir, icon);
num_files ++;
}
endmntent(m);
# else
//
// Normal WIN32 code uses drive bits...
//
DWORD drives; // Drive available bits
drives = GetLogicalDrives();
for (i = 'A'; i <= 'Z'; i ++, drives >>= 1)
if (drives & 1)
{
sprintf(filename, "%c:/", i);
if (i < 'C')
add(filename, icon);
else
add(filename, icon);
num_files ++;
}
# endif // __CYGWIN__
#elif defined(__EMX__)
//
// OS/2 code uses drive bits...
//
ULONG curdrive; // Current drive
ULONG drives; // Drive available bits
int start = 3; // 'C' (MRS - dunno if this is correct!)
DosQueryCurrentDisk(&curdrive, &drives);
drives >>= start - 1;
for (i = 'A'; i <= 'Z'; i ++, drives >>= 1)
if (drives & 1)
{
sprintf(filename, "%c:/", i);
add(filename, icon);
num_files ++;
}
#elif defined(__APPLE__) && !defined(__MWERKS__)
// MacOS X and Darwin use getfsstat() system call...
int numfs; // Number of file systems
struct statfs *fs; // Buffer for file system info
// We always have the root filesystem.
add("/", icon);
// Get the mounted filesystems...
numfs = getfsstat(NULL, 0, MNT_NOWAIT);
if (numfs > 0) {
// We have file systems, get them...
fs = new struct statfs[numfs];
getfsstat(fs, sizeof(struct statfs) * numfs, MNT_NOWAIT);
// Add filesystems to the list...
for (i = 0; i < numfs; i ++) {
// Ignore "/", "/dev", and "/.vol"...
if (fs[i].f_mntonname[1] && strcmp(fs[i].f_mntonname, "/dev") &&
strcmp(fs[i].f_mntonname, "/.vol")) {
snprintf(filename, sizeof(filename), "%s/", fs[i].f_mntonname);
add(filename, icon);
}
num_files ++;
}
// Free the memory used for the file system info array...
delete[] fs;
}
#else
//
// UNIX code uses /etc/fstab or similar...
//
FILE *mtab; // /etc/mtab or /etc/mnttab file
char line[1024]; // Input line
//
// Open the file that contains a list of mounted filesystems...
//
mtab = fopen("/etc/mnttab", "r"); // Fairly standard
if (mtab == NULL)
mtab = fopen("/etc/mtab", "r"); // More standard
if (mtab == NULL)
mtab = fopen("/etc/fstab", "r"); // Otherwise fallback to full list
if (mtab == NULL)
mtab = fopen("/etc/vfstab", "r"); // Alternate full list file
if (mtab != NULL)
{
while (fgets(line, sizeof(line), mtab) != NULL)
{
if (line[0] == '#' || line[0] == '\n')
continue;
if (sscanf(line, "%*s%4095s", filename) != 1)
continue;
strlcat(filename, "/", sizeof(filename));
// printf("FileBrowser::load() - adding \"%s\" to list...\n", filename);
add(filename, icon);
num_files ++;
}
fclose(mtab);
}
#endif // WIN32 || __EMX__
}
else
{
dirent **files; // Files in in directory
//
// Build the file list...
//
#if (defined(WIN32) && !defined(__CYGWIN__)) || defined(__EMX__)
strlcpy(filename, directory_, sizeof(filename));
i = strlen(filename) - 1;
if (i == 2 && filename[1] == ':' &&
(filename[2] == '/' || filename[2] == '\\'))
filename[2] = '/';
else if (filename[i] != '/' && filename[i] != '\\')
strlcat(filename, "/", sizeof(filename));
num_files = fltk::filename_list(filename, &files, sort);
#else
num_files = fltk::filename_list(directory_, &files, sort);
#endif /* WIN32 || __EMX__ */
if (num_files <= 0)
return (0);
for (i = 0, num_dirs = 0; i < num_files; i ++) {
if (strcmp(files[i]->d_name, "./") ) {
snprintf(filename, sizeof(filename), "%s/%s", directory_,
files[i]->d_name);
//bool ft = true; if (ft) {FileIcon::load_system_icons(); ft=false;}
icon = FileIcon::find(filename);
//printf("%s\n",files[i]->d_name);
if (!strcmp(files[i]->d_name, ".") || !strcmp(files[i]->d_name, "./") ||
!show_hidden_ && files[i]->d_name[0]=='.' && strncmp(files[i]->d_name,"../",2))
continue;
if ((icon && icon->type() == FileIcon::DIRECTORY) ||
fltk::filename_isdir(filename)) {
num_dirs ++;
this->insert(num_dirs-1, files[i]->d_name, icon);
} else if (filetype_ == FILES &&
fltk::filename_match(files[i]->d_name, pattern_)) {
add(files[i]->d_name, icon);
}
}
free(files[i]);
}
free(files);
}
return (num_files);
}
//
// 'FileBrowser::filter()' - Set the filename filter.
//
// I - Pattern string
void FileBrowser::filter(const char *pattern) {
// If pattern is NULL set the pattern to "*"...
if (pattern) pattern_ = pattern;
else pattern_ = "*";
}
////////////////////////////////////////////////////////////////
//#include <pixmaps/file_small.xpm>
//#include <fltk/xpmImage.h>
class FileItem : public Item {
public:
FileItem(const char * label, FileIcon * icon);
void draw();
private:
FileIcon* fileIcon_;
};
FileItem::FileItem(const char * label, FileIcon * icon) : Item(label) {
fileIcon_=icon;
textsize(14);
if(icon) icon->value(this,true);
}
void FileItem::draw() {
if (fileIcon_) fileIcon_->value(this,true);
Item::draw();
}
////////////////////////////////////////////////////////////////
void FileBrowser::add(const char *line, FileIcon *icon) {
this->begin();
FileItem * i = new FileItem(strdup(line),icon);
i->w((int) icon_size()); i->h(i->w());
this->end();
}
void FileBrowser::insert(int n, const char *label, FileIcon*icon) {
current(0);
FileItem * i = new FileItem(strdup(label),icon);
i->w((int) icon_size()); i->h(i->w());
Menu::insert(*i,n);
}
//
// End of "$Id: FileBrowser.cxx 5071 2006-05-02 21:57:08Z fabien $".
//

95
efiler/EDE_FileBrowser.h Normal file
View File

@ -0,0 +1,95 @@
//
// "$Id: FileBrowser.h 4926 2006-04-10 21:03:29Z fabien $"
//
// FileBrowser definitions.
//
// Copyright 1999-2006 by Michael Sweet.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
//
// Include necessary header files...
//
#ifndef fltk_FileBrowser_h
#define fltk_FileBrowser_h
#include <fltk/Browser.h>
#include <fltk/FileIcon.h>
#include <fltk/filename.h>
namespace fltk {
//
// FileBrowser class...
//
class FL_API FileBrowser : public Browser
{
int filetype_;
const char *directory_;
float icon_size_;
const char *pattern_;
public:
enum { FILES, DIRECTORIES };
FileBrowser(int, int, int, int, const char * = 0);
float icon_size() const {
return (icon_size_ <0? (2.0f* textsize()) : icon_size_);
}
void icon_size(float f) { icon_size_ = f; redraw(); };
void filter(const char *pattern);
const char *filter() const { return (pattern_); };
int load(const char *directory, File_Sort_F *sort = (File_Sort_F*) fltk::numericsort);
float textsize() const { return (Browser::textsize()); };
void textsize(float s) { Browser::textsize(s); icon_size_ = (uchar)(3 * s / 2); };
int filetype() const { return (filetype_); };
void filetype(int t) { filetype_ = t; };
const char * directory() const {return directory_;}
// adding or inserting a line into the fileBrowser
void insert(int n, const char* label, FileIcon* icon);
void insert(int n, const char* label, void* data){Menu::insert(n, label,data);}
void add(const char * line, FileIcon* icon);
// Showing or not showing the hidden files, that's the question:
public:
// sets this flag if you want to see the hidden files in the browser
void show_hidden(bool show) { show_hidden_= show; }
bool show_hidden() const {return show_hidden_;}
private:
bool show_hidden_;
};
}
#endif // !_Fl_File_Browser_H_
//
// End of "$Id: FileBrowser.h 4926 2006-04-10 21:03:29Z fabien $".
//

17
efiler/Makefile Normal file
View File

@ -0,0 +1,17 @@
CPPFILES = efiler.cpp ../edelib2/MimeType.cpp ../edelib2/Run.cpp ../edelib2/process.cpp ../edelib2/pty.cpp ../edelib2/Config.cpp ../edelib2/Icon.cpp ../edelib2/Util.cpp ../edelib2/about_dialog.cpp
TARGET = efiler
include ../makeinclude
install:
$(INSTALL_PROGRAM) $(TARGET) $(bindir)
$(INSTALL_LOCALE)
uninstall:
$(RM) $(bindir)/$(TARGET)
clean:
$(RM) $(TARGET)
$(RM) *.o

538
efiler/efiler.cpp Normal file
View File

@ -0,0 +1,538 @@
/*
* $Id$
*
* EFiler - EDE File Manager
* Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2000-2006 EDE Authors.
*
* This program is licenced under terms of the
* GNU General Public Licence version 2 or newer.
* See COPYING for details.
*/
#include <fltk/run.h>
#include <fltk/filename.h>
#include <fltk/Window.h>
#include <fltk/ScrollGroup.h>
#include <fltk/Button.h>
#include <fltk/ask.h>
#include <fltk/events.h>
#include <fltk/MenuBar.h>
#include <fltk/ItemGroup.h>
#include <fltk/Item.h>
#include <fltk/Divider.h>
#include <fltk/file_chooser.h>
#include <fltk/FileBrowser.h>
#include "../edelib2/about_dialog.h"
#include "../edelib2/Icon.h"
#include "../edelib2/MimeType.h"
#include "../edelib2/NLS.h"
#include "../edelib2/Run.h"
#include "../edelib2/Util.h"
#define DEFAULT_ICON "misc-vedran"
using namespace fltk;
using namespace edelib;
Window *win;
ScrollGroup* sgroup;
FileBrowser* fbrowser;
char current_dir[PATH_MAX];
static bool semaphore=false;
bool showhidden = false;
char **cut_copy_buffer = 0;
bool operation_is_copy = false;
// This is for the icon view, which should be redesigned to be like FileBrowser
void loaddir(const char* path);
void button_press(Widget* w, void*) {
if (event_clicks() || event_key() == ReturnKey) {
// run_program((char*)w->user_data(),true,false,true); // use elauncher
// char tmp[256];
// snprintf(tmp,255,"konsole --noclose -e %s",(char*)w->user_data());
// run_program(tmp,true,false,false);
if (!w->user_data() || (strlen((char*)w->user_data())==0))
alert(_("Unknown file type"));
else if (strncmp((char*)w->user_data(),"efiler ",7)==0) {
// don't launch new efiler instance
char tmp[PATH_MAX];
strncpy(tmp,(char*)w->user_data()+7,PATH_MAX);
// remove quotes
if (tmp[0] == '\'' || tmp[0] == '"')
memmove(tmp,tmp+1,strlen(tmp)-1);
int i=strlen(tmp)-2;
if (tmp[i] == '\'' || tmp[i] == '"')
tmp[i] = '\0';
loaddir(tmp);
} else {
fprintf(stderr, "Running: %s\n", (char*)w->user_data());
run_program((char*)w->user_data(),false,false,true);
}
}
if (event_is_click()) w->take_focus();
fprintf (stderr, "Event: %s (%d)\n",event_name(event()), event());
}
void loaddir(const char *path) {
// If user clicks too fast, it can cause problems
if (semaphore) {
return;
}
semaphore=true;
// Set current_dir
if (filename_isdir(path)) {
if (path[0] == '~') // Expand tilde
snprintf(current_dir,PATH_MAX,"%s/%s",getenv("HOME"),path);
else
strcpy(current_dir,path);
} else
strcpy(current_dir,getenv("HOME"));
// Trailing slash should always be there
if (current_dir[strlen(current_dir)-1] != '/') strcat(current_dir,"/");
fprintf (stderr, "loaddir(%s) = (%s)\n",path,current_dir);
// set window label
win->label(tasprintf(_("%s - File manager"), current_dir));
// Update file browser...
fbrowser->load(current_dir);
// some constants - TODO: move to configuration
int startx=0, starty=0;
int sizex=90, sizey=58;
int spacex=5, spacey=5;
// variables used later
Button **icon_array;
int icon_num=0;
dirent **files;
sgroup->remove_all();
sgroup->begin();
// list files
icon_num = fltk::filename_list(current_dir, &files, alphasort); // no sort needed because icons have coordinates
icon_array = (Button**) malloc (sizeof(Button*) * icon_num + 1);
// fill array with zeros, for easier detection if button exists
for (int i=0; i<icon_num; i++) icon_array[i]=0;
int myx=startx, myy=starty;
for (int i=0; i<icon_num; i++) {
char *n = files[i]->d_name; //shortcut
// don't show ./ (current directory)
if (strcmp(n,"./")==0) continue;
// hide files with dot except ../ (up directory)
if (!showhidden && (n[0] == '.') && (strcmp(n,"../")!=0)) continue;
// hide files ending with tilde (backup) - NOTE
if (!showhidden && (n[strlen(n)-1] == '~')) continue;
Button* o = new Button(myx, myy, sizex, sizey);
o->box(NO_BOX);
//o->labeltype(SHADOW_LABEL);
o->labelcolor(BLACK);
o->callback((Callback*)button_press);
o->align(ALIGN_INSIDE|ALIGN_CENTER|ALIGN_WRAP);
//o->when(WHEN_CHANGED|WHEN_ENTER_KEY);
o->label(n);
o->image(Icon::get(DEFAULT_ICON,Icon::SMALL));
myx=myx+sizex+spacex;
// 4 - edges
if (myx+sizex > sgroup->w()) { myx=startx; myy=myy+sizey+spacey; }
icon_array[i] = o;
}
sgroup->end();
// Give first icon the focus
sgroup->child(0)->take_focus();
sgroup->redraw();
// Detect icon mimetypes etc.
for (int i=0; i<icon_num; i++) {
// ignored files
if (!icon_array[i]) continue;
fltk::check(); // update interface
// get mime data
char fullpath[PATH_MAX];
snprintf (fullpath,PATH_MAX-1,"%s%s",current_dir,files[i]->d_name);
MimeType *m = new MimeType(fullpath);
fprintf(stderr,"Adding: %s (%s), cmd: '%s'\n", fullpath, m->id(), m->command());
// tooltip
char *tooltip;
if (strcmp(m->id(),"directory")==0)
asprintf(&tooltip, "%s - %s", files[i]->d_name, m->type_string());
else
asprintf(&tooltip, "%s (%s) - %s", files[i]->d_name, nice_size(filename_size(fullpath)), m->type_string());
icon_array[i]->tooltip(tooltip);
// icon
icon_array[i]->image(m->icon(Icon::SMALL));
// get command to execute
if (strcmp(files[i]->d_name,"../")==0) {
// up directory - we don't want ../ poluting filename
char exec[PATH_MAX];
int slashes=0, j;
for (j=strlen(current_dir); j>0; j--) {
if (current_dir[j]=='/') slashes++;
if (slashes==2) break;
}
if (slashes<2)
sprintf(exec,"efiler /");
else {
sprintf(exec,"efiler ");
strncat(exec,current_dir,j);
}
icon_array[i]->user_data(strdup(exec));
} else if (m->command() && (strlen(m->command())>0))
icon_array[i]->user_data(strdup(m->command()));
else
icon_array[i]->user_data(0);
// make sure label isn't too large
// TODO: move this to draw() method
int lx,ly;
icon_array[i]->measure_label(lx,ly);
int pos=strlen(icon_array[i]->label());
if (pos>252) pos=252;
char fixlabel[256];
while (lx>sizex) {
strncpy(fixlabel,icon_array[i]->label(),pos);
fixlabel[pos]='\0';
strcat(fixlabel,"...");
icon_array[i]->label(strdup(fixlabel));
icon_array[i]->measure_label(lx,ly);
pos--;
}
icon_array[i]->redraw();
delete m;
}
sgroup->redraw();
semaphore=false;
}
// List view
// Currently using fltk::FileBrowser which is quite ugly (so only callback is here)
void fbrowser_cb(Widget* w, void*) {
// Take only proper callbacks
if (!event_clicks() && event_key() != ReturnKey) return;
// Construct filename
const char *c = fbrowser->child(fbrowser->value())->label();
char filename[PATH_MAX];
if (strcmp(c,"../")==0) {
strcpy(filename,current_dir); // both are [PATH_MAX]
filename[strlen(filename)-1] = '\0'; // remove trailing slash in a directory
char *c2 = strrchr(filename,'/'); // find previous slash
if (c2) *(c2+1) = '\0'; // cut everything after this slash
else strcpy(filename,"/"); // if nothing is found, filename becomes "/"
} else
snprintf(filename,PATH_MAX,"%s%s",current_dir,c);
// Change directory
if (filename_isdir(filename))
loaddir(filename);
// Let elauncher handle this file...
else
run_program(filename,false,false,true);
}
// Menu callbacks
// File menu
void open_cb(Widget*, void*) {
Widget* w;
if (sgroup->visible())
w = sgroup->child(sgroup->focus_index());
else
w = fbrowser;
event_clicks(2);
w->do_callback();
}
void location_cb(Widget*, void*) {
const char *dir = dir_chooser(_("Choose location"),current_dir);
if (dir) loaddir(dir);
}
void quit_cb(Widget*, void*) {exit(0);}
// Edit menu
// Execute cut or copy operation when List View is active
void do_cut_copy_fbrowser(bool m_copy) {
// Count selected icons, for malloc
int num = fbrowser->children();
int nselected = 0;
for (int i=0; i<num; i++)
if (fbrowser->selected(i)) nselected++;
// Clear cut/copy buffer and optionally ungray the previously cutted icons
if (cut_copy_buffer) {
for (int i=0; cut_copy_buffer(i); i++)
free(cut_copy_buffer(i));
free(cut_copy_buffer);
if (!operation_is_copy) {
for (int i=0; i<num; i++)
fbrowser->child(i)->textcolor(BLACK); // FIXME: use color from style
}
}
// Allocate buffer
cut_copy_buffer = (char**)malloc(sizeof(char*) * (nselected+2));
// Add selected files to buffer and optionally grey icons (for cut effect)
int buf=0;
for (int i=0; i<=num; i++) {
if (fbrowser->selected(i)) {
asprintf(&cut_copy_buffer[buf], "%s%s", current_dir, fbrowser->child(i)->label());
if (!m_copy) fbrowser->child(i)->textcolor(GRAY50);
buf++;
}
}
cut_copy_buffer[buf] = 0;
operation_is_copy = copy;
// Deselect all
fbrowser->deselect();
}
// Execute cut or copy operation when Icon View is active
void do_cut_copy_sgroup(bool copy) {
// Group doesn't support type(MULTI) so only one item can be selected
// Will be changed
int num = fbrowser->children();
// Clear cut/copy buffer and optionally ungray the previously cutted icon
if (cut_copy_buffer) {
for (int i=0; cut_copy_buffer(i); i++)
free(cut_copy_buffer(i));
free(cut_copy_buffer);
if (!operation_is_copy) {
for (int i=0; i<num; i++)
sgroup->child(i)->textcolor(BLACK); // FIXME: use color from style
}
}
// Allocate buffer
cut_copy_buffer = (char**)malloc(sizeof(char*) * 3);
// Add selected files to buffer and optionally grey icons (for cut effect)
// FIXME: label doesn't contain filename!!
asprintf(&cut_copy_buffer[0], "%s%s", current_dir, sgroup->child(sgroup->focus_index())->label());
if (!m_copy) sgroup->child(sgroup->focus_index())->textcolor(GRAY50);
cut_copy_buffer[1]=0;
operation_is_copy=copy;
}
void cut_cb(Widget*, void*) {
if (sgroup->visible())
do_cut_copy_sgroup(false);
else
do_cut_copy_fbrowser(false);
}
void copy_cb(Widget*, void*) {
if (sgroup->visible())
do_cut_copy_sgroup(true);
else
do_cut_copy_fbrowser(true);
}
void paste_cb(Widget*, void*) {
}
// View menu
void iconsview_cb(Widget*,void*) {
if (sgroup->visible() && event_key() == F8Key) {
sgroup->hide();
fbrowser->show();
fbrowser->take_focus();
} else {
sgroup->show();
fbrowser->hide();
sgroup->take_focus();
}
}
void listview_cb(Widget*,void*) { sgroup->hide(); fbrowser->show(); }
void showhidden_cb(Widget* w, void*) {
Item *i = (Item*)w;
if (showhidden) {
showhidden=false;
i->clear();
} else {
showhidden=true;
i->set();
}
fbrowser->show_hidden(showhidden);
//fbrowser->redraw();
loaddir(current_dir);
}
// Help menu
void about_cb(Widget*, void*) { about_dialog("EFiler", "0.1", _("EDE File Manager"));}
// GUI design
int main (int argc, char **argv) {
win = new fltk::Window(600, 400);
win->color(WHITE);
win->begin();
// Main menu
{MenuBar *m = new MenuBar(0, 0, 600, 25);
m->begin();
{ItemGroup *o = new ItemGroup(_("&File"));
o->begin();
{Item *o = new Item(_("&Open"));
o->callback(open_cb);
o->shortcut(CTRL+'o');
}
{Item *o = new Item(_("Open &with..."));
//o->callback(open_cb);
//o->shortcut(CTRL+'o');
}
new Divider();
{Item *o = new Item(_("Open &location"));
o->callback(location_cb);
//o->shortcut(CTRL+'o');
}
new Divider();
{Item *o = new Item(_("&Quit"));
o->callback(quit_cb);
o->shortcut(CTRL+'q');
}
o->end();
}
{ItemGroup *o = new ItemGroup(_("&Edit"));
o->begin();
{Item *o = new Item(_("&Cut"));
o->callback(cut_cb);
o->shortcut(CTRL+'x');
}
{Item *o = new Item(_("C&opy"));
//o->callback(open_cb);
o->shortcut(CTRL+'c');
}
{Item *o = new Item(_("&Paste"));
//o->callback(open_cb);
o->shortcut(CTRL+'v');
}
{Item *o = new Item(_("&Rename"));
//o->callback(open_cb);
o->shortcut(F2Key);
}
{Item *o = new Item(_("&Delete"));
//o->callback(open_cb);
o->shortcut(DeleteKey);
}
new Divider();
{Item *o = new Item(_("&Preferences..."));
o->shortcut(CTRL+'p');
}
o->end();
}
{ItemGroup *o = new ItemGroup(_("&View"));
o->begin();
{Item *o = new Item(_("&Icons"));
o->type(Item::RADIO);
o->shortcut(F8Key);
o->set();
o->callback(iconsview_cb);
}
{Item *o = new Item(_("&Detailed List"));
o->type(Item::RADIO);
o->callback(listview_cb);
}
new Divider();
{Item *o = new Item(_("&Show hidden"));
o->type(Item::TOGGLE);
o->callback(showhidden_cb);
}
{Item *o = new Item(_("Directory &Tree"));
o->type(Item::TOGGLE);
o->shortcut(F9Key);
}
o->end();
}
{ItemGroup *o = new ItemGroup(_("&Help"));
o->begin();
{Item *o = new Item(_("&About File Manager"));
o->shortcut();
o->callback(about_cb);
}
o->end();
}
m->end();
}
// Icon view
{sgroup = new ScrollGroup(0, 25, 600, 375);
sgroup->box(DOWN_BOX);
sgroup->color(WHITE);
// sgroup->highlight_color(WHITE);
// sgroup->selection_color(WHITE);
sgroup->align(ALIGN_LEFT|ALIGN_TOP);
// g->label("There are no files in current directory");
}
// List view
{fbrowser = new FileBrowser(0, 25, 600, 375);
fbrowser->box(DOWN_BOX);
fbrowser->color(WHITE);
fbrowser->callback(fbrowser_cb);
// sgroup->align(ALIGN_LEFT|ALIGN_TOP);
// g->label("There are no files in current directory");
fbrowser->when(WHEN_ENTER_KEY);
//fbrowser->labelsize(12);
fbrowser->type(Browser::MULTI);
fbrowser->hide();
}
win->end();
win->resizable(sgroup);
win->icon(Icon::get("folder",Icon::TINY));
win->show();
if (argc==1) { // No params
loaddir ("");
} else {
loaddir (argv[1]);
}
return fltk::run();
}

87
efiler/mimetypes.conf Normal file
View File

@ -0,0 +1,87 @@
# EDE mimetypes description
#
# Format:
# id|description|handler program|icon|wildcard for filename (extension)|wildcard for file command output|classic mime type
#
# - id - short string; to setup subtypes, just use slash (/) as separator in ID
# - description - what is shown in gui
# - handler program - filename will be appended, specify any needed parameters for opening - THIS WILL BE MOVED INTO SEPARATE FILE (for handling multiple programs etc.)
# - icon - just name, don't give extension or path
# - extension - will be used only if multiple types have same file command match. You don't need to give asterisk (*) i.e. .png. If there are multiple extensions, separate them with slash (/). Actually, "extension" can be any part of filename, but I can't think of use for this
# - file output - relevant part of output from `file -bLnNp $filename`
# - classic mime type - what is used for interchange i.e. text/plain - may be used for matching if other methods fail
#
# This is how mimetype resolving is supposed to work: if there is exactly one match for `file`
# output, this is what we use. If there are multiple, the largest match is used. If there are
# no results or several results with same size we look at extension, then at classic mime type
# (using -i parameter to `file`).
#
bitmap|Picture (Unknown)|eimage|image|||
bitmap/bmp|Picture (BMP)|eimage|image|.bmp|PC bitmap data|image/bmp
bitmap/gif|Picture (GIF)|eimage|image|.gif|GIF image data|image/gif
bitmap/jpeg|Picture (JPEG)|eimage|image|.jpg/.jpeg|JPEG image data|image/png
bitmap/png|Picture (PNG)|eimage|image|.png|PNG image data|image/png
bitmap/psd|Picture (Adobe PhotoShop)||image|.psd|Adobe Photoshop Image|image/x-photoshop
text|Plain text|enotepad|txt|.txt/|text|text/plain
#text/unicode|Plain text|enotepad|txt|.txt|Unicode * text|text/plain # we need wildcard support in file output :(
text/c|C code|enotepad|source_c|.c/.h|C program text|text/x-c
text/config|Program configuration|enotepad|ascii|.conf/rc|text|text/plain
text/config/xml|Program configuration (XML)|enotepad|ascii|.conf/rc|XML document text|text/xml
text/cpp|C++ code|enotepad|source_cpp|.cpp/.cxx/.h|C++ program text|text/x-c++
text/cpp/lame|Plain text|enotepad|txt||C++ program text|text/plain
text/desktop|Shortcut|elauncher|exec|.desktop/.directory|text|text/plain
text/diff|File difference|fldiff|kmultiple|.diff/.patch|'diff' output text|
text/html|Web page (HTML)|konqueror|html|.html/.htm|HTML document text|text/html
text/html/lame|Web page (HTML)|konqueror|html|.html/.htm|text|text/html # for pages that dont have the proper headers, and are so detected as simple ascii text
text/java|Java code|enotepad|source_java|.java|Perl5 module source text|text/x-java # misdetection in find
text/php|PHP code|enotepad|source_php|.php/.php3|PHP script text|text/plain
text/po|Program translation resource|kbabel|ascii|.po|PO (gettext message catalogue) text|text/x-po
text/readme|Read this first!|enotepad|txt2|README|text|text/plain
text/script|Program (shell script)|elauncher|empty|.sh|script text|application/x-shellscript
text/script/perl|Program (Perl script)|elauncher|empty|.pl|perl script text|application/x-perl
text/xml|XML text|enotepad|txt|.xml/|XML document text|text/xml
office|Office document|ooffice2.0|document||Document|
office/db|Database|ooffice2.0|empty||| # find icon for database!
office/db/sqlite|Database (SQLite)|ooffice2.0|empty|.db|SQLite database|
office/ms|Microsoft Office document|ooffice2.0|document||Microsoft Office Document|
office/odf|Open Document Format (ODF) document|ooffice2.0|document||
office/pdf|PDF document|xpdf|pdf|.pdf|PDF document|application/pdf
office/spread|Spreadsheet|ooffice2.0|spreadsheet|||
office/spread/ods|Spreadsheet (OpenOffice.org 2.0)|ooffice2.0|spreadsheet|.ods|Zip archive data|
office/spread/sxc|Spreadsheet (OpenOffice.org 1.x)|ooffice2.0|spreadsheet|.sxc|Zip archive data|
office/spread/xls|Spreadsheet (MS Excel)|ooffice2.0|spreadsheet|.xls|Microsoft Office Document|application/msexcel
office/word|Word document|ooffice2.0|wordprocessing|||
office/word/doc|Word document (MS Word)|ooffice2.0|wordprocessing|.doc|Microsoft Office Document|application/msword
office/word/odt|Word document (OpenOffice.org 2.0)|ooffice2.0|wordprocessing|.odt|Zip archive data|
office/word/sxw|Word document (OpenOffice.org 1.x)|ooffice2.0|wordprocessing|.sxw|Zip archive data|
empty|Empty file|enotepad|misc-vedran||empty|
archive|Archive||tar||archive| # Consider using the term "Compressed file(s)"
archive/bz2|Archive (BZ2)||tar|.bz2|bzip2 compressed data|application/x-gzip
archive/gz|Archive (GZ)||tar|.gz|gzip compressed data|application/x-gzip
archive/rar|Archive (RAR)||tar|.rar|RAR archive data|application/x-rar
archive/tar|Archive (TAR)||tar|.tar|tar archive|application/x-tar
archive/targz|Archive (TAR.GZ)||tar|.tar.gz|gzip compressed data|application/x-gzip
archive/tarbz2|Archive (TAR.BZ2)||tar|.tar.bz2|bzip2 compressed data|application/x-bzip2
archive/zip|Archive (ZIP)||tar|.zip|Zip archive data|application/x-zip
install|Program installation|efiler|tgz|||
install/makefile|Program instalation (source)|einstaller|make||make commands text|text/x-makefile
install/rpm|Program installation (RPM)|einstaller|rpm|.rpm|RPM|application/x-rpm
program|Program|elauncher|empty|||
program/elf|Program|elauncher|empty||ELF 32-bit LSB executable|application/x-executable
program/elf/o|Program part||misc-vedran||ELF 32-bit LSB relocatable|application/x-object
program/jar|Java program|java -jar|empty|.jar|Zip archive data|application/x-zip
program/java-class|Java program|java|empty|.class|compiled Java class data|
program/swf|Macromedia Flash program|mozilla-firefox|empty|.swf|Macromedia Flash data|
video|Video|mplayer|video||video|
video/qt|Video (QuickTime)|mplayer|video|.mov|Apple QuickTime movie|video/quicktime
video/xvid|Video (XviD)|mplayer|video|.avi|video: XviD|video/x-msvideo
audio|Audio|xmms|sound||audio|
audio/mp3|Audio (MP3)|xmms|sound|.mp3|MPEG ADTS, layer III|audio/mpeg
audio/ogg|Audio (OGG)|xmms|sound|.ogg|Ogg data, Vorbis audio|application/ogg
image|Filesystem image||binary|.img|filesystem data|
image/ext2|Filesystem image (ext2)||binary|.img|ext2 filesystem data|
image/boot|Boot floppy image||3floppy_unmount|.img|x86 boot sector|
vector|Drawing (unknown)|inkscape|vectorgfx|||
vector/svg|Drawing (SVG)|inkscape|vectorgfx|.svg|XML document text| # hope they fix file to detect this properly
font|Font||font||font|
font/ttf|Font (TrueType)||font_truetype|.ttf|TrueType font data|