00001 #include "bcdelete.h"
00002 #include "bcfilebox.h"
00003 #include "bclistboxitem.h"
00004 #include "bcnewfolder.h"
00005 #include "bcpixmap.h"
00006 #include "bcresources.h"
00007 #include "bctitle.h"
00008 #include "clip.h"
00009 #include "condition.h"
00010 #include "filesystem.h"
00011 #include "language.h"
00012 #include "mutex.h"
00013 #include <string.h>
00014 #include <sys/stat.h>
00015
00016
00017
00018
00019
00020
00021
00022 BC_FileBoxRecent::BC_FileBoxRecent(BC_FileBox *filebox, int x, int y)
00023 : BC_ListBox(x,
00024 y,
00025 250,
00026 200,
00027 LISTBOX_TEXT,
00028 &filebox->recent_dirs,
00029 0,
00030 0,
00031 1,
00032 0,
00033 1)
00034 {
00035 this->filebox = filebox;
00036 }
00037
00038 int BC_FileBoxRecent::handle_event()
00039 {
00040 if(get_selection(0, 0) >= 0)
00041 {
00042 filebox->submit_dir(get_selection(0, 0)->get_text());
00043 }
00044 return 1;
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 BC_FileBoxListBox::BC_FileBoxListBox(int x, int y, BC_FileBox *filebox)
00058 : BC_ListBox(x,
00059 y,
00060 filebox->get_listbox_w(),
00061 filebox->get_listbox_h(y),
00062 filebox->get_display_mode(),
00063 filebox->list_column,
00064 filebox->column_titles,
00065 filebox->column_width,
00066 filebox->columns,
00067 0,
00068 0,
00069 filebox->select_multiple ? LISTBOX_MULTIPLE : LISTBOX_SINGLE,
00070 ICON_LEFT,
00071 0)
00072 {
00073 this->filebox = filebox;
00074 set_sort_column(filebox->sort_column);
00075 set_sort_order(filebox->sort_order);
00076 set_allow_drag_column(1);
00077 }
00078
00079 BC_FileBoxListBox::~BC_FileBoxListBox()
00080 {
00081 }
00082
00083 int BC_FileBoxListBox::handle_event()
00084 {
00085 filebox->submit_file(filebox->textbox->get_text());
00086 return 1;
00087 }
00088
00089 int BC_FileBoxListBox::selection_changed()
00090 {
00091 BC_ListBoxItem *item = get_selection(
00092 filebox->column_of_type(FILEBOX_NAME), 0);
00093
00094 if(item)
00095 {
00096 char path[BCTEXTLEN];
00097 strcpy(path, item->get_text());
00098 filebox->textbox->update(path);
00099 filebox->fs->extract_dir(filebox->directory, path);
00100 filebox->fs->extract_name(filebox->filename, path);
00101 filebox->fs->complete_path(path);
00102 strcpy(filebox->current_path, path);
00103 strcpy(filebox->submitted_path, path);
00104 }
00105 return 1;
00106 }
00107
00108 int BC_FileBoxListBox::column_resize_event()
00109 {
00110 for(int i = 0; i < filebox->columns; i++)
00111 BC_WindowBase::get_resources()->filebox_columnwidth[i] =
00112 filebox->column_width[i] =
00113 get_column_width(i);
00114 return 1;
00115 }
00116
00117 int BC_FileBoxListBox::sort_order_event()
00118 {
00119 get_resources()->filebox_sortcolumn = filebox->sort_column = get_sort_column();
00120 get_resources()->filebox_sortorder = filebox->sort_order = get_sort_order();
00121 filebox->refresh();
00122 return 1;
00123 }
00124
00125 int BC_FileBoxListBox::move_column_event()
00126 {
00127 filebox->move_column(get_from_column(), get_to_column());
00128 return 1;
00129 }
00130
00131 int BC_FileBoxListBox::evaluate_query(int list_item, char *string)
00132 {
00133 ArrayList<BC_ListBoxItem*> *column =
00134 &filebox->list_column[filebox->column_of_type(FILEBOX_NAME)];
00135 return(column->values[list_item]->get_color() != get_resources()->directory_color &&
00136 strcmp(string, column->values[list_item]->get_text()) <= 0);
00137 }
00138
00139
00140
00141
00142 BC_FileBoxTextBox::BC_FileBoxTextBox(int x, int y, BC_FileBox *filebox)
00143 : BC_TextBox(x, y, filebox->get_w() - 50, 1, filebox->filename)
00144 {
00145 this->filebox = filebox;
00146 }
00147
00148 BC_FileBoxTextBox::~BC_FileBoxTextBox()
00149 {
00150 }
00151
00152 int BC_FileBoxTextBox::handle_event()
00153 {
00154
00155 return 1;
00156 }
00157
00158
00159
00160
00161 BC_FileBoxDirectoryText::BC_FileBoxDirectoryText(int x, int y, BC_FileBox *filebox)
00162 : BC_TextBox(x, y, filebox->get_w() - 40, 1, filebox->fs->get_current_dir())
00163 {
00164 this->filebox = filebox;
00165 }
00166
00167 int BC_FileBoxDirectoryText::handle_event()
00168 {
00169 char *path;
00170 path = get_text();
00171
00172 if(!filebox->fs->is_dir(path))
00173 {
00174 filebox->fs->change_dir(path);
00175 filebox->refresh();
00176 update(strcat(filebox->fs->get_current_dir(),"/"));
00177 }
00178 return 0;
00179 }
00180
00181
00182
00183
00184
00185 BC_FileBoxFilterText::BC_FileBoxFilterText(int x, int y, BC_FileBox *filebox)
00186 : BC_TextBox(x, y, filebox->get_w() - 50, 1, filebox->get_resources()->filebox_filter)
00187 {
00188 this->filebox = filebox;
00189 }
00190
00191 int BC_FileBoxFilterText::handle_event()
00192 {
00193 filebox->update_filter(get_text());
00194 return 0;
00195 }
00196
00197
00198 BC_FileBoxFilterMenu::BC_FileBoxFilterMenu(int x, int y, BC_FileBox *filebox)
00199 : BC_ListBox(x,
00200 y,
00201 filebox->get_w() - 30,
00202 120,
00203 LISTBOX_TEXT,
00204 &filebox->filter_list,
00205 0,
00206 0,
00207 1,
00208 0,
00209 1)
00210 {
00211 this->filebox = filebox;
00212 set_tooltip(_("Change the filter"));
00213 }
00214
00215 int BC_FileBoxFilterMenu::handle_event()
00216 {
00217 filebox->filter_text->update(
00218 get_selection(filebox->column_of_type(FILEBOX_NAME), 0)->get_text());
00219 filebox->update_filter(
00220 get_selection(filebox->column_of_type(FILEBOX_NAME), 0)->get_text());
00221 return 0;
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 BC_FileBoxCancel::BC_FileBoxCancel(BC_FileBox *filebox)
00234 : BC_CancelButton(filebox)
00235 {
00236 this->filebox = filebox;
00237 set_tooltip(_("Cancel the operation"));
00238 }
00239
00240 BC_FileBoxCancel::~BC_FileBoxCancel()
00241 {
00242 }
00243
00244 int BC_FileBoxCancel::handle_event()
00245 {
00246
00247 filebox->newfolder_thread->interrupt();
00248 filebox->set_done(1);
00249 return 1;
00250 }
00251
00252
00253
00254
00255
00256
00257
00258 BC_FileBoxUseThis::BC_FileBoxUseThis(BC_FileBox *filebox)
00259 : BC_Button(filebox->get_w() / 2 -
00260 BC_WindowBase::get_resources()->usethis_button_images[0]->get_w() / 2,
00261 filebox->ok_button->get_y(),
00262 BC_WindowBase::get_resources()->usethis_button_images)
00263 {
00264 this->filebox = filebox;
00265 set_tooltip(_("Submit the directory"));
00266 }
00267
00268 BC_FileBoxUseThis::~BC_FileBoxUseThis()
00269 {
00270 }
00271
00272 int BC_FileBoxUseThis::handle_event()
00273 {
00274 filebox->submit_file(filebox->textbox->get_text(), 1);
00275 return 1;
00276 }
00277
00278
00279
00280
00281
00282 BC_FileBoxOK::BC_FileBoxOK(BC_FileBox *filebox)
00283 : BC_OKButton(filebox,
00284 !filebox->want_directory ?
00285 BC_WindowBase::get_resources()->ok_images :
00286 BC_WindowBase::get_resources()->filebox_descend_images)
00287 {
00288 this->filebox = filebox;
00289 if(filebox->want_directory)
00290 set_tooltip(_("Descend directory"));
00291 else
00292 set_tooltip(_("Submit the file"));
00293 }
00294
00295 BC_FileBoxOK::~BC_FileBoxOK()
00296 {
00297 }
00298
00299 int BC_FileBoxOK::handle_event()
00300 {
00301 filebox->submit_file(filebox->textbox->get_text());
00302 return 1;
00303 }
00304
00305
00306
00307
00308
00309
00310 BC_FileBoxText::BC_FileBoxText(int x, int y, BC_FileBox *filebox)
00311 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_text_images)
00312 {
00313 this->filebox = filebox;
00314 set_tooltip(_("Display text"));
00315 }
00316 int BC_FileBoxText::handle_event()
00317 {
00318 filebox->create_listbox(filebox->listbox->get_x(), filebox->listbox->get_y(), LISTBOX_TEXT);
00319 return 1;
00320 }
00321
00322
00323 BC_FileBoxIcons::BC_FileBoxIcons(int x, int y, BC_FileBox *filebox)
00324 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_icons_images)
00325 {
00326 this->filebox = filebox;
00327 set_tooltip(_("Display icons"));
00328 }
00329 int BC_FileBoxIcons::handle_event()
00330 {
00331 filebox->create_listbox(filebox->listbox->get_x(), filebox->listbox->get_y(), LISTBOX_ICONS);
00332 return 1;
00333 }
00334
00335
00336 BC_FileBoxNewfolder::BC_FileBoxNewfolder(int x, int y, BC_FileBox *filebox)
00337 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_newfolder_images)
00338 {
00339 this->filebox = filebox;
00340 set_tooltip(_("Create new folder"));
00341 }
00342 int BC_FileBoxNewfolder::handle_event()
00343 {
00344 filebox->newfolder_thread->start_new_folder();
00345 return 1;
00346 }
00347
00348 BC_FileBoxUpdir::BC_FileBoxUpdir(int x, int y, BC_FileBox *filebox)
00349 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_updir_images)
00350 {
00351 this->filebox = filebox;
00352 set_tooltip(_("Up a directory"));
00353 }
00354 int BC_FileBoxUpdir::handle_event()
00355 {
00356
00357 sprintf(string, _(".."));
00358 filebox->submit_file(string);
00359 return 1;
00360 }
00361
00362 BC_FileBoxDelete::BC_FileBoxDelete(int x, int y, BC_FileBox *filebox)
00363 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_delete_images)
00364 {
00365 this->filebox = filebox;
00366 set_tooltip(_("Delete files"));
00367 }
00368 int BC_FileBoxDelete::handle_event()
00369 {
00370 filebox->unlock_window();
00371 filebox->delete_thread->start();
00372 filebox->lock_window("BC_FileBoxDelete::handle_event");
00373 return 1;
00374 }
00375
00376 BC_FileBoxReload::BC_FileBoxReload(int x, int y, BC_FileBox *filebox)
00377 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_reload_images)
00378 {
00379 this->filebox = filebox;
00380 set_tooltip(_("Refresh"));
00381 }
00382 int BC_FileBoxReload::handle_event()
00383 {
00384 filebox->refresh();
00385 return 1;
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 BC_FileBox::BC_FileBox(int x,
00398 int y,
00399 char *init_path,
00400 char *title,
00401 char *caption,
00402 int show_all_files,
00403 int want_directory,
00404 int multiple_files,
00405 int h_padding)
00406 : BC_Window(title,
00407 x,
00408 y,
00409 BC_WindowBase::get_resources()->filebox_w,
00410 BC_WindowBase::get_resources()->filebox_h,
00411 10,
00412 10,
00413 1,
00414 0,
00415 1)
00416 {
00417 fs = new FileSystem;
00418 if(want_directory)
00419 {
00420 fs->set_want_directory();
00421 columns = DIRBOX_COLUMNS;
00422 }
00423 else
00424 {
00425 columns = FILEBOX_COLUMNS;
00426 }
00427
00428 list_column = new ArrayList<BC_ListBoxItem*>[columns];
00429 column_type = new int[columns];
00430 column_width = new int[columns];
00431
00432 filter_text = 0;
00433 filter_popup = 0;
00434 usethis_button = 0;
00435
00436 strcpy(this->caption, caption);
00437 strcpy(this->current_path, init_path);
00438 strcpy(this->submitted_path, init_path);
00439 select_multiple = multiple_files;
00440 this->want_directory = want_directory;
00441 if(show_all_files) fs->set_show_all();
00442 fs->complete_path(this->current_path);
00443 fs->complete_path(this->submitted_path);
00444 fs->extract_dir(directory, this->current_path);
00445 fs->extract_name(filename, this->current_path);
00446
00447
00448 if(want_directory)
00449 {
00450 for(int i = 0; i < columns; i++)
00451 {
00452 column_type[i] = get_resources()->dirbox_columntype[i];
00453 column_width[i] = get_resources()->dirbox_columnwidth[i];
00454 column_titles[i] = BC_FileBox::columntype_to_text(column_type[i]);
00455 }
00456 sort_column = get_resources()->dirbox_sortcolumn;
00457 sort_order = get_resources()->dirbox_sortorder;
00458 }
00459 else
00460 {
00461 for(int i = 0; i < columns; i++)
00462 {
00463 column_type[i] = get_resources()->filebox_columntype[i];
00464 column_width[i] = get_resources()->filebox_columnwidth[i];
00465 column_titles[i] = BC_FileBox::columntype_to_text(column_type[i]);
00466 }
00467 sort_column = get_resources()->filebox_sortcolumn;
00468 sort_order = get_resources()->filebox_sortorder;
00469 }
00470
00471
00472
00473
00474 if(fs->update(directory))
00475 {
00476 sprintf(this->current_path, "~");
00477 fs->complete_path(this->current_path);
00478 fs->update(this->current_path);
00479 strcpy(directory, fs->get_current_dir());
00480 sprintf(filename, "");
00481 }
00482
00483
00484 this->h_padding = h_padding;
00485 delete_thread = new BC_DeleteThread(this);
00486 }
00487
00488 BC_FileBox::~BC_FileBox()
00489 {
00490
00491 delete newfolder_thread;
00492 delete fs;
00493 delete_tables();
00494 for(int i = 0; i < TOTAL_ICONS; i++)
00495 delete icons[i];
00496 filter_list.remove_all_objects();
00497 delete [] list_column;
00498 delete [] column_type;
00499 delete [] column_width;
00500 delete delete_thread;
00501 recent_dirs.remove_all_objects();
00502 }
00503
00504 int BC_FileBox::create_objects()
00505 {
00506 int x = 10, y = 10;
00507 BC_Resources *resources = BC_WindowBase::get_resources();
00508 int directory_title_margin = MAX(20,
00509 resources->filebox_text_images[0]->get_h());
00510
00511
00512 create_history();
00513
00514 if(!want_directory)
00515 {
00516 filter_list.append(new BC_ListBoxItem("*"));
00517 filter_list.append(new BC_ListBoxItem("[*.ifo][*.vob]"));
00518 filter_list.append(new BC_ListBoxItem("[*.mp2][*.mp3][*.wav]"));
00519 filter_list.append(new BC_ListBoxItem("[*.avi][*.mpg][*.m2v][*.m1v][*.mov]"));
00520 filter_list.append(new BC_ListBoxItem("heroine*"));
00521 filter_list.append(new BC_ListBoxItem("*.xml"));
00522 fs->set_filter(get_resources()->filebox_filter);
00523 }
00524
00525 fs->update(directory);
00526 create_icons();
00527 create_tables();
00528
00529 add_subwindow(ok_button = new BC_FileBoxOK(this));
00530 if(want_directory)
00531 add_subwindow(usethis_button = new BC_FileBoxUseThis(this));
00532 add_subwindow(cancel_button = new BC_FileBoxCancel(this));
00533
00534 add_subwindow(new BC_Title(x, y, caption));
00535 x = get_w() - resources->filebox_icons_images[0]->get_w() - 10;
00536 add_subwindow(icon_button = new BC_FileBoxIcons(x, y, this));
00537 x -= resources->filebox_text_images[0]->get_w() + 5;
00538 add_subwindow(text_button = new BC_FileBoxText(x, y, this));
00539 x -= resources->filebox_newfolder_images[0]->get_w() + 5;
00540 add_subwindow(folder_button = new BC_FileBoxNewfolder(x, y, this));
00541 x -= resources->filebox_reload_images[0]->get_w() + 5;
00542 add_subwindow(reload_button = new BC_FileBoxReload(x, y, this));
00543 x -= resources->filebox_delete_images[0]->get_w() + 5;
00544 add_subwindow(delete_button = new BC_FileBoxDelete(x, y, this));
00545 x -= resources->filebox_updir_images[0]->get_w() + 5;
00546 add_subwindow(updir_button = new BC_FileBoxUpdir(x, y, this));
00547
00548 x = 10;
00549 y += directory_title_margin + 3;
00550
00551 add_subwindow(recent_popup = new BC_FileBoxRecent(this,
00552 x,
00553 y));
00554 add_subwindow(directory_title = new BC_FileBoxDirectoryText(x, y, this));
00555 directory_title->reposition_window(
00556 x,
00557 y,
00558 get_w() - recent_popup->get_w() - 20,
00559 1);
00560 recent_popup->reposition_window(
00561 x + directory_title->get_w(),
00562 y,
00563 directory_title->get_w(),
00564 recent_popup->get_h());
00565
00566
00567
00568
00569
00570
00571 x = 10;
00572 y += directory_title->get_h() + 5;
00573 listbox = 0;
00574
00575 create_listbox(x, y, get_display_mode());
00576 y += listbox->get_h() + 10;
00577 add_subwindow(textbox = new BC_FileBoxTextBox(x, y, this));
00578
00579 y += textbox->get_h() + 10;
00580 if(!want_directory)
00581 {
00582 add_subwindow(filter_text = new BC_FileBoxFilterText(x, y, this));
00583 add_subwindow(filter_popup =
00584 new BC_FileBoxFilterMenu(x + filter_text->get_w(), y, this));
00585 }
00586
00587
00588 listbox->activate();
00589 newfolder_thread = new BC_NewFolderThread(this);
00590
00591 show_window();
00592 return 0;
00593 }
00594
00595 int BC_FileBox::get_listbox_w()
00596 {
00597 return get_w() - 20;
00598 }
00599
00600 int BC_FileBox::get_listbox_h(int y)
00601 {
00602 int result = get_h() -
00603 y -
00604 h_padding;
00605 if(!want_directory)
00606 result -= BC_WindowBase::get_resources()->filebox_margin;
00607 else
00608 result -= BC_WindowBase::get_resources()->dirbox_margin;
00609
00610 return result;
00611 }
00612
00613 int BC_FileBox::create_icons()
00614 {
00615 for(int i = 0; i < TOTAL_ICONS; i++)
00616 {
00617 icons[i] = new BC_Pixmap(this,
00618 BC_WindowBase::get_resources()->type_to_icon[i],
00619 PIXMAP_ALPHA);
00620 }
00621 return 0;
00622 }
00623
00624 int BC_FileBox::resize_event(int w, int h)
00625 {
00626 draw_background(0, 0, w, h);
00627 flash();
00628
00629
00630
00631
00632
00633
00634 if(usethis_button)
00635 usethis_button->reposition_window(w / 2 - 50, h - (get_h() - usethis_button->get_y()));
00636 if(filter_popup) filter_popup->reposition_window(w - (get_w() - filter_popup->get_x()),
00637 h - (get_h() - filter_popup->get_y()),
00638 w - 30);
00639 if(filter_text) filter_text->reposition_window(filter_text->get_x(),
00640 h - (get_h() - filter_text->get_y()),
00641 w - (get_w() - filter_text->get_w()),
00642 1);
00643 directory_title->reposition_window(
00644 directory_title->get_x(),
00645 directory_title->get_y(),
00646 get_w() - recent_popup->get_w() - 20,
00647 1);
00648 recent_popup->reposition_window(
00649 directory_title->get_x() + directory_title->get_w(),
00650 directory_title->get_y(),
00651 directory_title->get_w() + recent_popup->get_w(),
00652 recent_popup->get_h());
00653 textbox->reposition_window(textbox->get_x(),
00654 h - (get_h() - textbox->get_y()),
00655 w - (get_w() - textbox->get_w()),
00656 1);
00657 listbox->reposition_window(listbox->get_x(),
00658 listbox->get_y(),
00659 w - (get_w() - listbox->get_w()),
00660 h - (get_h() - listbox->get_h()));
00661 icon_button->reposition_window(w - (get_w() - icon_button->get_x()),
00662 icon_button->get_y());
00663 text_button->reposition_window(w - (get_w() - text_button->get_x()),
00664 text_button->get_y());
00665 folder_button->reposition_window(w - (get_w() - folder_button->get_x()),
00666 folder_button->get_y());
00667 reload_button->reposition_window(w - (get_w() - reload_button->get_x()),
00668 reload_button->get_y());
00669 delete_button->reposition_window(w - (get_w() - delete_button->get_x()),
00670 delete_button->get_y());
00671 updir_button->reposition_window(w - (get_w() - updir_button->get_x()),
00672 updir_button->get_y());
00673 set_w(w);
00674 set_h(h);
00675 get_resources()->filebox_w = get_w();
00676 get_resources()->filebox_h = get_h();
00677 return 1;
00678 }
00679
00680 int BC_FileBox::keypress_event()
00681 {
00682 switch(get_keypress())
00683 {
00684 case 'w':
00685 if(ctrl_down()) set_done(1);
00686 return 1;
00687 break;
00688 }
00689 return 0;
00690 }
00691
00692 int BC_FileBox::close_event()
00693 {
00694 set_done(1);
00695 return 1;
00696 }
00697
00698 int BC_FileBox::handle_event()
00699 {
00700 return 0;
00701 }
00702
00703 int BC_FileBox::extract_extension(char *out, const char *in)
00704 {
00705 int i;
00706
00707 for(i = strlen(in)-1; i > 0 && in[i] != '.'; i--)
00708 {
00709 ;
00710 }
00711 if(in[i] == '.') {
00712 i++;
00713 strcpy(out, &in[i]);
00714 }
00715 else
00716 out[0] = '\0';
00717 return 0;
00718 }
00719
00720 int BC_FileBox::create_tables()
00721 {
00722 delete_tables();
00723 char string[BCTEXTLEN];
00724 BC_ListBoxItem *new_item;
00725
00726 fs->set_sort_order(sort_order);
00727 fs->set_sort_field(column_type[sort_column]);
00728
00729 fs->update(0);
00730 for(int i = 0; i < fs->total_files(); i++)
00731 {
00732 FileItem *file_item = fs->get_entry(i);
00733 int is_dir = file_item->is_dir;
00734 BC_Pixmap* icon = get_icon(file_item->name, is_dir);
00735
00736
00737 new_item = new BC_ListBoxItem(file_item->name,
00738 icon,
00739 is_dir ? get_resources()->directory_color : get_resources()->file_color);
00740 if(is_dir) new_item->set_searchable(0);
00741 list_column[column_of_type(FILEBOX_NAME)].append(new_item);
00742
00743
00744 if(!want_directory)
00745 {
00746 if(!is_dir)
00747 {
00748 sprintf(string, "%lld", file_item->size);
00749 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
00750 }
00751 else
00752 {
00753 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
00754 }
00755
00756 list_column[column_of_type(FILEBOX_SIZE)].append(new_item);
00757 }
00758
00759
00760 if(!is_dir || 1)
00761 {
00762 static char *month_text[13] =
00763 {
00764 "Null",
00765 "Jan",
00766 "Feb",
00767 "Mar",
00768 "Apr",
00769 "May",
00770 "Jun",
00771 "Jul",
00772 "Aug",
00773 "Sep",
00774 "Oct",
00775 "Nov",
00776 "Dec"
00777 };
00778 sprintf(string,
00779 "%s %d, %d",
00780 month_text[file_item->month],
00781 file_item->day,
00782 file_item->year);
00783 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
00784 }
00785 else
00786 {
00787 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
00788 }
00789
00790 list_column[column_of_type(FILEBOX_DATE)].append(new_item);
00791
00792
00793 if(!want_directory)
00794 {
00795 if(!is_dir)
00796 {
00797 extract_extension(string, file_item->name);
00798 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
00799 }
00800 else
00801 {
00802 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
00803 }
00804 list_column[column_of_type(FILEBOX_EXTENSION)].append(new_item);
00805 }
00806 }
00807
00808 return 0;
00809 }
00810
00811 int BC_FileBox::delete_tables()
00812 {
00813 for(int j = 0; j < columns; j++)
00814 {
00815 list_column[j].remove_all_objects();
00816 }
00817 return 0;
00818 }
00819
00820 BC_Pixmap* BC_FileBox::get_icon(char *path, int is_dir)
00821 {
00822 char *suffix = strrchr(path, '.');
00823 int icon_type = ICON_UNKNOWN;
00824
00825 if(is_dir) return icons[ICON_FOLDER];
00826
00827 if(suffix)
00828 {
00829 suffix++;
00830 if(*suffix != 0)
00831 {
00832 for(int i = 0; i < TOTAL_SUFFIXES; i++)
00833 {
00834 if(!strcasecmp(suffix, BC_WindowBase::get_resources()->suffix_to_type[i].suffix))
00835 {
00836 icon_type = BC_WindowBase::get_resources()->suffix_to_type[i].icon_type;
00837 break;
00838 }
00839 }
00840 }
00841 }
00842
00843 return icons[icon_type];
00844 }
00845
00846 char* BC_FileBox::columntype_to_text(int type)
00847 {
00848 switch(type)
00849 {
00850 case FILEBOX_NAME:
00851 return FILEBOX_NAME_TEXT;
00852 break;
00853 case FILEBOX_SIZE:
00854 return FILEBOX_SIZE_TEXT;
00855 break;
00856 case FILEBOX_DATE:
00857 return FILEBOX_DATE_TEXT;
00858 break;
00859 case FILEBOX_EXTENSION:
00860 return FILEBOX_EXTENSION_TEXT;
00861 break;
00862 }
00863 return "";
00864 }
00865
00866 int BC_FileBox::column_of_type(int type)
00867 {
00868 for(int i = 0; i < columns; i++)
00869 if(column_type[i] == type) return i;
00870 return 0;
00871 }
00872
00873
00874
00875 int BC_FileBox::refresh()
00876 {
00877 create_tables();
00878 listbox->set_master_column(column_of_type(FILEBOX_NAME), 0);
00879 listbox->update(list_column,
00880 column_titles,
00881 column_width,
00882 columns,
00883 0,
00884 0,
00885 -1,
00886 1);
00887
00888 return 0;
00889 }
00890
00891 int BC_FileBox::update_filter(char *filter)
00892 {
00893 fs->set_filter(filter);
00894 fs->update(0);
00895 refresh();
00896 strcpy(get_resources()->filebox_filter, filter);
00897
00898 return 0;
00899 }
00900
00901
00902 void BC_FileBox::move_column(int src, int dst)
00903 {
00904 ArrayList<BC_ListBoxItem*> *new_columns =
00905 new ArrayList<BC_ListBoxItem*>[columns];
00906 int *new_types = new int[columns];
00907 int *new_widths = new int[columns];
00908
00909
00910 for(int out_column = 0, in_column = 0;
00911 out_column < columns;
00912 out_column++,
00913 in_column++)
00914 {
00915
00916 if(out_column == dst)
00917 {
00918 for(int i = 0; i < list_column[src].total; i++)
00919 {
00920 new_columns[out_column].append(list_column[src].values[i]);
00921 }
00922 new_types[out_column] = column_type[src];
00923 new_widths[out_column] = column_width[src];
00924 in_column--;
00925 }
00926 else
00927 {
00928
00929 if(in_column == src) in_column++;
00930 for(int i = 0; i < list_column[src].total; i++)
00931 {
00932 new_columns[out_column].append(list_column[in_column].values[i]);
00933 }
00934 new_types[out_column] = column_type[in_column];
00935 new_widths[out_column] = column_width[in_column];
00936 }
00937 }
00938
00939
00940 delete [] list_column;
00941 delete [] column_type;
00942 delete [] column_width;
00943 list_column = new_columns;
00944 column_type = new_types;
00945 column_width = new_widths;
00946
00947 for(int i = 0; i < columns; i++)
00948 {
00949 get_resources()->filebox_columntype[i] = column_type[i];
00950 get_resources()->filebox_columnwidth[i] = column_width[i];
00951 column_titles[i] = BC_FileBox::columntype_to_text(column_type[i]);
00952 }
00953
00954
00955 refresh();
00956 }
00957
00958
00959 int BC_FileBox::submit_dir(char *dir)
00960 {
00961 strcpy(directory, dir);
00962 fs->join_names(current_path, directory, filename);
00963 strcpy(submitted_path, current_path);
00964 fs->change_dir(dir);
00965 refresh();
00966 directory_title->update(fs->get_current_dir());
00967 if(want_directory)
00968 textbox->update(fs->get_current_dir());
00969 else
00970 textbox->update(filename);
00971 listbox->reset_query();
00972 return 0;
00973 }
00974
00975 int BC_FileBox::submit_file(char *path, int use_this)
00976 {
00977
00978 if(!path[0])
00979 {
00980
00981 strcpy(this->current_path, directory);
00982
00983 strcpy(this->submitted_path, directory);
00984 update_history();
00985
00986 filename[0] = 0;
00987 set_done(0);
00988 return 0;
00989 }
00990
00991
00992 if(!fs->is_dir(path) && !use_this)
00993 {
00994 fs->change_dir(path);
00995 refresh();
00996 directory_title->update(fs->get_current_dir());
00997 strcpy(this->current_path, fs->get_current_dir());
00998 strcpy(this->submitted_path, fs->get_current_dir());
00999 strcpy(this->directory, fs->get_current_dir());
01000 filename[0] = 0;
01001 if(want_directory)
01002 textbox->update(fs->get_current_dir());
01003 else
01004 textbox->update("");
01005 listbox->reset_query();
01006 return 1;
01007 }
01008 else
01009
01010 {
01011 fs->extract_dir(directory, path);
01012 fs->extract_name(filename, path);
01013 fs->complete_path(path);
01014 strcpy(this->current_path, path);
01015 strcpy(this->submitted_path, path);
01016 update_history();
01017 newfolder_thread->interrupt();
01018 set_done(0);
01019 return 0;
01020 }
01021 return 0;
01022 }
01023
01024 void BC_FileBox::update_history()
01025 {
01026
01027 BC_Resources *resources = get_resources();
01028 int new_slot = FILEBOX_HISTORY_SIZE - 1;
01029 for(int i = FILEBOX_HISTORY_SIZE - 1; i >= 0; i--)
01030 {
01031 if(!strcmp(resources->filebox_history[i], directory))
01032 {
01033
01034 while(i > 0)
01035 {
01036 strcpy(resources->filebox_history[i],
01037 resources->filebox_history[i - 1]);
01038 if(resources->filebox_history[i][0]) new_slot--;
01039 i--;
01040 }
01041 break;
01042 }
01043 else
01044 if(resources->filebox_history[i][0])
01045 new_slot--;
01046 else
01047 break;
01048 }
01049
01050 if(new_slot < 0)
01051 {
01052 for(int i = FILEBOX_HISTORY_SIZE - 1; i > 0; i--)
01053 {
01054 strcpy(resources->filebox_history[i],
01055 resources->filebox_history[i - 1]);
01056 }
01057 new_slot = 0;
01058 }
01059 strcpy(resources->filebox_history[new_slot], directory);
01060
01061 create_history();
01062 recent_popup->update(&recent_dirs,
01063 0,
01064 0,
01065 1);
01066 }
01067
01068 void BC_FileBox::create_history()
01069 {
01070 BC_Resources *resources = get_resources();
01071 recent_dirs.remove_all_objects();
01072 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
01073 {
01074 if(resources->filebox_history[i][0])
01075 {
01076 recent_dirs.append(new BC_ListBoxItem(resources->filebox_history[i]));
01077 }
01078 }
01079 }
01080
01081
01082 int BC_FileBox::get_display_mode()
01083 {
01084 return top_level->get_resources()->filebox_mode;
01085 }
01086
01087 void BC_FileBox::create_listbox(int x, int y, int mode)
01088 {