Some simple patches:

1.   Simpler randomize list  in playlist.cpp
2.   Don't choke on invalid glyphs in ttfont.cpp
3.   Add Drag Drop between playlists in browserlist.cpp
4.   FileSelector remembers last directory after selection in fileselector.cpp


Some of these patches were previously submitted, I never recieved confirmation 
nor rejection and they've never shown up in the archive so I thought I would try again.

Any thoughts of opening up the CVS to non-team members or adding more team members?



-- 
Kristian G. Kvilekval
email:[EMAIL PROTECTED] office:(805)893-4178 http://www.cs.ucsb.edu/~kris
Index: base/src/playlist.cpp
===================================================================
RCS file: /src/repository/freeamp/base/src/playlist.cpp,v
retrieving revision 1.118
diff -c -r1.118 playlist.cpp
*** base/src/playlist.cpp       2001/12/17 05:13:15     1.118
--- base/src/playlist.cpp       2002/01/10 02:49:51
***************
*** 428,475 ****
      if (!toBeShuffled)
          toBeShuffled = &m_shuffleList;
  
!     int max = toBeShuffled->size();
!     vector<PlaylistItem *> tempShuffled;
! 
!     srand((unsigned int)time(NULL));
!     
!     int i;
!     vector<bool> usedList;
!     for (i = 0; i < max; i++)
!     {
!         usedList.push_back(false);
!     }
! 
!     bool used = true;
!     int  index = 0;
!     int  lastindex = 0;
! 
!     for (i = 0; i < max; i++) 
!     {
!         while (used)
!         {
!             index = (int)((double)rand() / (RAND_MAX + 1.0) * max);
!             if (usedList[index] == false)
!                 used = false;
!             if (max - i > 50 && abs(index - lastindex) < 10)
!                 used = true;
!         } 
!         usedList[index] = true;
!         PlaylistItem *dupe = (*toBeShuffled)[index];
!         tempShuffled.push_back(dupe);
!         used = true;
!         lastindex = index;
!     }
! 
!     toBeShuffled->erase(toBeShuffled->begin(), toBeShuffled->end());
!     vector<PlaylistItem *>::iterator iter = tempShuffled.begin();
!     for (; iter != tempShuffled.end(); iter++) 
!         toBeShuffled->push_back(*iter);
  }
  
  Error PlaylistManager::SetCurrentItem(PlaylistItem* item)
  {
!     return SetCurrentIndex(IndexOf(item));
  }
  
  PlaylistItem*  PlaylistManager::GetCurrentItem()
--- 428,442 ----
      if (!toBeShuffled)
          toBeShuffled = &m_shuffleList;
  
!     random_shuffle ((*toBeShuffled).begin(), (*toBeShuffled).end());
  }
  
+ 
  Error PlaylistManager::SetCurrentItem(PlaylistItem* item)
  {
!    int index ;
!    index = IndexOf(item);
!    return SetCurrentIndex(index);
  }
  
  PlaylistItem*  PlaylistManager::GetCurrentItem()
***************
*** 493,500 ****
  {
     m_mutex.Acquire();
     index = CheckIndex(index);
!    if(m_shuffle)
!       index = InternalIndexOf(&m_shuffleList, ItemAt(index));
     InternalSetCurrentIndex(index);
     m_mutex.Release();
     return kError_NoErr;
--- 460,468 ----
  {
     m_mutex.Acquire();
     index = CheckIndex(index);
!    if (m_shuffle) {
!      index = InternalIndexOf(&m_shuffleList, ItemAt(index));
!    }
     InternalSetCurrentIndex(index);
     m_mutex.Release();
     return kError_NoErr;
***************
*** 536,555 ****
          if(!(kPlaylistMode_RepeatOne == m_repeatMode) || userAction)
          {
              index++;
- 
-             if( (index >= count) && 
-                 (m_repeatMode == kPlaylistMode_RepeatAll || userAction))
-             {
-                 index = 0;
  
!                 if(m_shuffle)
!                 {
!                     ShuffleIt();
!                 }
!             }
!             else if(index >= count)
              {
!                 index = m_current;
              }
          }
  
--- 504,519 ----
          if(!(kPlaylistMode_RepeatOne == m_repeatMode) || userAction)
          {
              index++;
  
!             if( (index >= count) )
              {
!                if(m_repeatMode == kPlaylistMode_RepeatAll || userAction)
!                {
!                   index = 0;
!                   if (m_shuffle) ShuffleIt();
!                }
!                else
!                   index = m_current;
              }
          }
  
***************
*** 570,594 ****
  
      Error result = kError_NoErr;
      uint32 count = m_masterList.size();
!     uint32 index = m_current;
      
      if(count)
      {
          if(!(kPlaylistMode_RepeatOne == m_repeatMode) || userAction)
          {
!             if( (index == 0) && 
!                 (m_repeatMode == kPlaylistMode_RepeatAll || userAction))
              {
!                 index = count - 1;
! 
!                 if(m_shuffle)
                  {
!                     ShuffleIt();
                  }
!             }
!             else if(index != 0)
!             {
!                 index--;
              }
          }
  
--- 534,555 ----
  
      Error result = kError_NoErr;
      uint32 count = m_masterList.size();
!     int32 index = m_current;
      
      if(count)
      {
          if(!(kPlaylistMode_RepeatOne == m_repeatMode) || userAction)
          {
!             index--;
!             if (index < 0)
              {
!                 if  (m_repeatMode == kPlaylistMode_RepeatAll || userAction)
                  {
!                     index = count - 1;
!                     if(m_shuffle)  ShuffleIt();
                  }
!                 else
!                    index = 0;
              }
          }
  
Index: ui/freeamp/unix/src/GTKPreferenceWindow.cpp
===================================================================
RCS file: /src/repository/freeamp/ui/freeamp/unix/src/GTKPreferenceWindow.cpp,v
retrieving revision 1.64
diff -c -r1.64 GTKPreferenceWindow.cpp
*** ui/freeamp/unix/src/GTKPreferenceWindow.cpp 2001/10/16 05:03:41     1.64
--- ui/freeamp/unix/src/GTKPreferenceWindow.cpp 2002/01/10 02:49:51
***************
*** 1701,1706 ****
--- 1701,1708 ----
      m_pThemeMan->GetCurrentTheme(originalValues.currentTheme);
      m_oThemeList.clear();
  
+     cout << "Theme = " << originalValues.currentTheme << endl;
+ 
      gtk_clist_freeze(GTK_CLIST(themeList));
      gtk_clist_clear(GTK_CLIST(themeList));
  
***************
*** 1810,1815 ****
--- 1812,1819 ----
      gtk_widget_show(themeList);
  
      UpdateThemeList();
+     cout << "index = " << currentValues.listboxIndex << endl;
+     cout << "Theme = " << currentValues.currentTheme << endl;
  
      GtkWidget *vbox = gtk_vbox_new(FALSE, 5);
      gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 5);
Index: ui/freeamp/unix/src/ttfont.cpp
===================================================================
RCS file: /src/repository/freeamp/ui/freeamp/unix/src/ttfont.cpp,v
retrieving revision 1.8
diff -c -r1.8 ttfont.cpp
*** ui/freeamp/unix/src/ttfont.cpp      2000/10/17 10:24:05     1.8
--- ui/freeamp/unix/src/ttfont.cpp      2002/01/10 02:49:51
***************
*** 193,199 ****
       {
        j = text[i];
  
!       if (!TT_VALID(f->glyphs[j]))
           continue;
  
        TT_Get_Glyph_Metrics(f->glyphs[j], &metrics);
--- 193,199 ----
       {
        j = text[i];
  
!       if (j >= f->num_glyph || !TT_VALID(f->glyphs[j]))
           continue;
  
        TT_Get_Glyph_Metrics(f->glyphs[j], &metrics);
Index: ui/musicbrowser/unix/include/fileselector.h
===================================================================
RCS file: /src/repository/freeamp/ui/musicbrowser/unix/include/fileselector.h,v
retrieving revision 1.5
diff -c -r1.5 fileselector.h
*** ui/musicbrowser/unix/include/fileselector.h 2001/10/27 23:20:21     1.5
--- ui/musicbrowser/unix/include/fileselector.h 2002/01/10 02:49:51
***************
*** 34,40 ****
  
  class FileSelector {
   public:
!     FileSelector(const char *);
    
      bool Run(bool runMain = true);
      void SetExtended() { extended = true; }
--- 34,40 ----
  
  class FileSelector {
   public:
!     FileSelector(const char *, const char *defdir = 0);
    
      bool Run(bool runMain = true);
      void SetExtended() { extended = true; }
***************
*** 42,51 ****
--- 42,53 ----
                                  return (char *)returnpath.c_str(); 
                              else return NULL; 
                            }
+     char *getDir () { return  (defaultdir != "")?(char*)defaultdir.c_str():NULL; } 
  
   private:
      string returnpath;
      string title;
+     string defaultdir;
      bool extended;
      bool ok;
      bool done;
Index: ui/musicbrowser/unix/include/gtkmusicbrowser.h
===================================================================
RCS file: /src/repository/freeamp/ui/musicbrowser/unix/include/gtkmusicbrowser.h,v
retrieving revision 1.65
diff -c -r1.65 gtkmusicbrowser.h
*** ui/musicbrowser/unix/include/gtkmusicbrowser.h      2001/04/13 02:28:10     1.65
--- ui/musicbrowser/unix/include/gtkmusicbrowser.h      2002/01/10 02:49:51
***************
*** 87,92 ****
--- 87,93 ----
  
  enum {
     TARGET_TREE = 1, 
+    TARGET_LIST,
     TARGET_STRING,
     TARGET_URL
  };
***************
*** 313,318 ****
--- 314,320 ----
    public:
  
      vector<PlaylistItem *> *GetTreeSelection(void);
+     vector<PlaylistItem *> *GetListSelection(void);
      bool iSetShuffleMode;
  
      ClickState GetClickState() { return m_clickState; }
Index: ui/musicbrowser/unix/src/browserlist.cpp
===================================================================
RCS file: /src/repository/freeamp/ui/musicbrowser/unix/src/browserlist.cpp,v
retrieving revision 1.20
diff -c -r1.20 browserlist.cpp
*** ui/musicbrowser/unix/src/browserlist.cpp    2001/12/10 20:41:54     1.20
--- ui/musicbrowser/unix/src/browserlist.cpp    2002/01/10 02:49:51
***************
*** 619,644 ****
      p->m_plSelected.erase(row);
  }
  
  static gboolean list_drag_drop_internal(GtkWidget *widget,
                                          GdkDragContext *context,
                                          gint x, gint y, guint time,
                                          GTKMusicBrowser *p)
  {
!     GList *list = context->targets;
      GdkAtom atom = gdk_atom_intern("gtk-clist-drag-reorder", FALSE);
      GdkAtom tree = gdk_atom_intern("tree-drag", FALSE);
      GdkAtom plain = gdk_atom_intern("text/plain", FALSE);
      GdkAtom html = gdk_atom_intern("text/html", FALSE);
!     while (list) {
!         if (((int)atom == GPOINTER_TO_INT(list->data)) ||
!             ((int)tree == GPOINTER_TO_INT(list->data)) ||
!             ((int)plain == GPOINTER_TO_INT(list->data)) ||
!             ((int)html == GPOINTER_TO_INT(list->data))) {
!             gtk_drag_get_data(widget, context, GPOINTER_TO_INT(list->data), 
                                time);
              return TRUE;
          }
!         list = list->next;
      }
      return FALSE;
  }
--- 619,702 ----
      p->m_plSelected.erase(row);
  }
  
+ 
+ vector<PlaylistItem *> *GTKMusicBrowser::GetListSelection() 
+ {
+   vector<PlaylistItem *> *newlist = new vector<PlaylistItem *>;
+ 
+   // Get the entire selected list ..
+   // for now just one
+   
+   PlaylistItem *item = new PlaylistItem (*m_plm->ItemAt(m_lastindex));
+   newlist->push_back (item);
+ 
+   return newlist;
+ }
+ 
+ 
+ 
+ static void list_source_destroy(gpointer data) 
+ {
+ }
+ 
+ static void list_drag_begin(GtkWidget *w, GdkDragContext *context,
+                             GTKMusicBrowser *p)
+ {
+     //cout << "list_drag_begin" << endl;
+     g_return_if_fail(w != NULL);
+     g_return_if_fail(context != NULL);
+ 
+     void *test = g_dataset_get_data(context, "list-drag-source");
+     if (!test)
+         g_dataset_set_data_full(context, "list-drag-source", p,
+                                 list_source_destroy);
+ }
+ 
+ static void list_drag_data_get(GtkWidget *w, GdkDragContext *context,
+                                GtkSelectionData *selection_data, guint info,
+                                guint time, GtkWidget *widget)
+ {
+     //cout << "list_drag_data_get" << endl;
+ 
+     // Put the currently selected item into the gtk selection
+ 
+     if (selection_data->target == gdk_atom_intern("list-drag", FALSE)) {
+         GTKMusicBrowser *p = (GTKMusicBrowser *)g_dataset_get_data(context,
+                                                                    
+"list-drag-source");
+ 
+         vector<PlaylistItem *> *newlist = p->GetListSelection();
+         gtk_selection_data_set(selection_data, selection_data->target,
+                                0, (guchar *)&newlist, sizeof(vector<PlaylistItem 
+*>*));
+         //cout << (char*)(((void*)widget  == (void*)p)?"same widget":"boohoo") << 
+endl;
+     }
+ 
+ 
+ }
+ 
  static gboolean list_drag_drop_internal(GtkWidget *widget,
                                          GdkDragContext *context,
                                          gint x, gint y, guint time,
                                          GTKMusicBrowser *p)
  {
!     GList *targets = context->targets;
      GdkAtom atom = gdk_atom_intern("gtk-clist-drag-reorder", FALSE);
      GdkAtom tree = gdk_atom_intern("tree-drag", FALSE);
+     GdkAtom list = gdk_atom_intern("list-drag", FALSE);
      GdkAtom plain = gdk_atom_intern("text/plain", FALSE);
      GdkAtom html = gdk_atom_intern("text/html", FALSE);
! 
!     cout << "list_drag_drop_internal" << endl;
!     while (targets) {
!         if (((int)atom == GPOINTER_TO_INT(targets->data)) ||
!             ((int)tree == GPOINTER_TO_INT(targets->data)) ||
!             ((int)list == GPOINTER_TO_INT(targets->data)) ||
!             ((int)plain == GPOINTER_TO_INT(targets->data)) ||
!             ((int)html == GPOINTER_TO_INT(targets->data))) {
!             gtk_drag_get_data(widget, context, GPOINTER_TO_INT(targets->data), 
                                time);
              return TRUE;
          }
!         targets = targets->next;
      }
      return FALSE;
  }
***************
*** 730,736 ****
  {
      if (widget == gtk_drag_get_source_widget(context))
          return;
!     if (info == TARGET_TREE) {
          if (data->length == sizeof(vector<PlaylistItem *> *)) {
              vector<PlaylistItem *> *newlist;
              newlist = *((vector<PlaylistItem *>**)(data->data));
--- 788,794 ----
  {
      if (widget == gtk_drag_get_source_widget(context))
          return;
!     if (info == TARGET_TREE || info == TARGET_LIST) {
          if (data->length == sizeof(vector<PlaylistItem *> *)) {
              vector<PlaylistItem *> *newlist;
              newlist = *((vector<PlaylistItem *>**)(data->data));
***************
*** 1119,1133 ****
                         GTK_SIGNAL_FUNC(unset_current_index_internal), this);
      gtk_clist_set_selection_mode(GTK_CLIST(playlistList),
                                   GTK_SELECTION_EXTENDED);
!     GtkTargetEntry new_clist_target_table[4] = {
          {"gtk-clist-drag-reorder", 0, 0},
          {"tree-drag", 0, TARGET_TREE},
          {"text/plain", 0, TARGET_STRING},
          {"text/html", 0, TARGET_URL},
      };
      GTK_CLIST_SET_FLAG(GTK_CLIST(playlistList), CLIST_REORDERABLE);
      gtk_drag_dest_set(playlistList, (GtkDestDefaults)0,
!                       (GtkTargetEntry *)&new_clist_target_table, 4,
                        GDK_ACTION_MOVE);
      gtk_signal_connect(GTK_OBJECT(playlistList), "drag_leave",
                         GTK_SIGNAL_FUNC(list_drag_leave_internal), this);
--- 1177,1192 ----
                         GTK_SIGNAL_FUNC(unset_current_index_internal), this);
      gtk_clist_set_selection_mode(GTK_CLIST(playlistList),
                                   GTK_SELECTION_EXTENDED);
!     GtkTargetEntry new_clist_target_table[5] = {
          {"gtk-clist-drag-reorder", 0, 0},
          {"tree-drag", 0, TARGET_TREE},
+         {"list-drag", 0, TARGET_LIST},
          {"text/plain", 0, TARGET_STRING},
          {"text/html", 0, TARGET_URL},
      };
      GTK_CLIST_SET_FLAG(GTK_CLIST(playlistList), CLIST_REORDERABLE);
      gtk_drag_dest_set(playlistList, (GtkDestDefaults)0,
!                       (GtkTargetEntry *)&new_clist_target_table, 5,
                        GDK_ACTION_MOVE);
      gtk_signal_connect(GTK_OBJECT(playlistList), "drag_leave",
                         GTK_SIGNAL_FUNC(list_drag_leave_internal), this);
***************
*** 1141,1146 ****
--- 1200,1218 ----
                         GTK_SIGNAL_FUNC(list_keypress), this);
      gtk_signal_connect(GTK_OBJECT(playlistList), "button_press_event",
                         GTK_SIGNAL_FUNC(list_clicked), this);
+ 
+     
+     GtkTargetEntry new_clist_source_table[4] = {
+         {"list-drag", 0, TARGET_LIST}
+     };
+     gtk_drag_source_set (GTK_WIDGET(playlistList), GDK_BUTTON1_MASK,
+                          new_clist_source_table, 1, GDK_ACTION_MOVE);
+     gtk_signal_connect(GTK_OBJECT(playlistList), "drag_data_get",
+                        GTK_SIGNAL_FUNC(list_drag_data_get), this);
+     gtk_signal_connect(GTK_OBJECT(playlistList), "drag_begin",
+                        GTK_SIGNAL_FUNC(list_drag_begin), this);
+     
+ 
  
      playlistPopup = gtk_item_factory_new(GTK_TYPE_MENU, "<plist_popup>",
                                           NULL);
Index: ui/musicbrowser/unix/src/fileselector.cpp
===================================================================
RCS file: /src/repository/freeamp/ui/musicbrowser/unix/src/fileselector.cpp,v
retrieving revision 1.8
diff -c -r1.8 fileselector.cpp
*** ui/musicbrowser/unix/src/fileselector.cpp   2000/09/28 08:08:03     1.8
--- ui/musicbrowser/unix/src/fileselector.cpp   2002/01/10 02:49:51
***************
*** 32,44 ****
  #include "fileselector.h"
  #include "utility.h"
  
! FileSelector::FileSelector(const char *windowtitle)
  {
      title = windowtitle;
      returnpath = "";
      extended = true;
      ok = false;
      done = false;
  }
  
  gboolean filesel_destroy(GtkWidget *widget, gpointer p)
--- 32,45 ----
  #include "fileselector.h"
  #include "utility.h"
  
! FileSelector::FileSelector(const char *windowtitle, const char *defdir)
  {
      title = windowtitle;
      returnpath = "";
      extended = true;
      ok = false;
      done = false;
+     if (defdir) defaultdir = defdir;
  }
  
  gboolean filesel_destroy(GtkWidget *widget, gpointer p)
***************
*** 94,101 ****
          strcpy(path_temp, "./");
          path_temp = (char *)realloc(path_temp, strlen(path_temp) + 1);
      }
!     else
          tempdir[0] = '\0';
  
      raw_path = gtk_entry_get_text(GTK_ENTRY(gfile->selection_entry));
      while (row) {
--- 95,106 ----
          strcpy(path_temp, "./");
          path_temp = (char *)realloc(path_temp, strlen(path_temp) + 1);
      }
!     else { 
          tempdir[0] = '\0';
+         defaultdir = path_temp;
+       defaultdir += "/.";
+     }
+       
  
      raw_path = gtk_entry_get_text(GTK_ENTRY(gfile->selection_entry));
      while (row) {
***************
*** 140,145 ****
--- 145,155 ----
      if (extended)
          gtk_clist_set_selection_mode(GTK_CLIST(GTK_FILE_SELECTION(filesel)->
                                       file_list), GTK_SELECTION_EXTENDED);
+ 
+     if (defaultdir.length() != 0) 
+         gtk_file_selection_set_filename (GTK_FILE_SELECTION(filesel),
+                                        defaultdir.c_str());
+ 
      gtk_widget_show(filesel);
  
      if (runMain)
Index: ui/musicbrowser/unix/src/gtkmusicbrowser.cpp
===================================================================
RCS file: /src/repository/freeamp/ui/musicbrowser/unix/src/gtkmusicbrowser.cpp,v
retrieving revision 1.130
diff -c -r1.130 gtkmusicbrowser.cpp
*** ui/musicbrowser/unix/src/gtkmusicbrowser.cpp        2001/12/10 20:41:54     1.130
--- ui/musicbrowser/unix/src/gtkmusicbrowser.cpp        2002/01/10 02:49:52
***************
*** 753,762 ****
  
  void GTKMusicBrowser::AddFileCMD()
  {
      bool playNow = true;
      m_context->prefs->GetPrefBoolean(kPlayImmediatelyPref, &playNow);
  
!     FileSelector *filesel = new FileSelector("Select a file to play");
      if (filesel->Run(false)) {
          char *returnpath = filesel->GetReturnPath();
          char *ext = m_context->player->GetExtension(returnpath);
--- 753,763 ----
  
  void GTKMusicBrowser::AddFileCMD()
  {
+    static string lastfile;
      bool playNow = true;
      m_context->prefs->GetPrefBoolean(kPlayImmediatelyPref, &playNow);
  
!     FileSelector *filesel = new FileSelector("Select a file to 
play",lastfile.c_str());
      if (filesel->Run(false)) {
          char *returnpath = filesel->GetReturnPath();
          char *ext = m_context->player->GetExtension(returnpath);
***************
*** 787,792 ****
--- 788,794 ----
                      delete [] filereturn;
                  }
              }
+             lastfile =  filesel->getDir();
              delete [] ext;
              delete [] tempurl;
          }

Reply via email to