Ejemplo n.º 1
0
void Desktop::unfocus_all(void) {
	DesktopIcon *o;
	for(int i = 0; i < children(); i++) {
		if(NOT_SELECTABLE(child(i))) continue;

		o = (DesktopIcon*)child(i);
		o->do_unfocus();
		o->fast_redraw();
	}
}
Ejemplo n.º 2
0
/*
 * Tries to figure out icon below mouse. It is alternative to Fl::belowmouse() since with this we hunt 
 * only icons, not other childs (wallpaper, menu), which can be returned by Fl::belowmouse() and bad 
 * things be hapened.
 */
DesktopIcon* Desktop::below_mouse(int px, int py) {
	DesktopIcon *o;

	for(int i = 0; i < children(); i++) {
		if(NOT_SELECTABLE(child(i))) continue;
		
		o = (DesktopIcon*)child(i);
		if(o->x() < px && o->y() < py && px < (o->x() + o->h()) && py < (o->y() + o->h()))
			return o;
	}

	return NULL;
}
Ejemplo n.º 3
0
bool Desktop::save_icons_positions(void) {
	DesktopConfig pos;
	DesktopIcon   *o;
	char          *base;

	for(int i = 0; i < children(); i++) {
		if(NOT_SELECTABLE(child(i))) continue;

		o = (DesktopIcon*)child(i);
		base = get_basename(o->get_path());
		pos.set(base, "X", o->x());
		pos.set(base, "Y", o->y());
	}
	
	return pos.save(ICONS_POS_FILE);
}
Ejemplo n.º 4
0
void Desktop::select_in_area(void) {
	if(!selbox->show) return;

	int ax = selbox->x;
	int ay = selbox->y;
	int aw = selbox->w;
	int ah = selbox->h;

	if(aw < 0) {
		ax += aw;
		aw = -aw;
	} else if(!aw)
		aw = 1;

	if(ah < 0) {
		ay += ah;
		ah = -ah;
	} else if(!ah)
		ah = 1;

	/*
	 * XXX: This function can fail since icon coordinates are absolute (event_x_root)
	 * but selbox use relative (event_root). It will work as expected if desktop is at x=0 y=0.
	 * This should be checked further.
	 */
	DesktopIcon* o;
	for(int i = 0; i < children(); i++) {
		if(NOT_SELECTABLE(child(i))) continue;
		o = (DesktopIcon*)child(i);
		
		if(intersects(ax, ay, ax+aw, ay+ah, o->x(), o->y(), o->w()+o->x(), o->h()+o->y())) {
			if(!o->is_focused()) {
				o->do_focus();
				/* updated from Desktop::draw() */
				o->damage(EDE_DESKTOP_DAMAGE_CHILD_LABEL);
			}
		} else {
			if(o->is_focused()) {
				o->do_unfocus();
				o->fast_redraw();
			}
		}
	} 
}
Ejemplo n.º 5
0
void Desktop::arrange_icons(void) {
	int lw = icon_opts ? icon_opts->label_maxwidth : 75;
	int X = (lw / 5) + 10;
	int Y = 10;
	int H = h();
	DesktopIcon *o;
	
	for(int i = 0; i < children(); i++) {
		if(NOT_SELECTABLE(child(i))) continue;
		
		o = (DesktopIcon*)child(i);
		o->position(X, Y);
		Y += o->h() + (o->h() / 2);
		
		if(Y + (o->h() / 2) > H) {
			Y = 10;
			X += lw + (o->w() / 2);
		}
	}
}
void PLSelector::createItems()
{
    /* PL */
    playlistItem = putPLData( addItem( PL_ITEM_TYPE, N_("Playlist"), true ),
                              THEPL->p_playing );
    playlistItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PL ) );
    playlistItem->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/playlist" ) );
    setCurrentItem( playlistItem->treeItem() );

    /* ML */
    PLSelItem *ml = putPLData( addItem( PL_ITEM_TYPE, N_("Media Library"), true ),
                              THEPL->p_media_library );
    ml->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_ML ) );
    ml->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/library" ) );

#ifdef MEDIA_LIBRARY
    /* SQL ML */
    ml = addItem( SQL_ML_TYPE, "SQL Media Library" )->treeItem();
    ml->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/library" ) );
#endif

    /* SD nodes */
    QTreeWidgetItem *mycomp = addItem( CATEGORY_TYPE, N_("My Computer"), false, true )->treeItem();
    QTreeWidgetItem *devices = addItem( CATEGORY_TYPE, N_("Devices"), false, true )->treeItem();
    QTreeWidgetItem *lan = addItem( CATEGORY_TYPE, N_("Local Network"), false, true )->treeItem();
    QTreeWidgetItem *internet = addItem( CATEGORY_TYPE, N_("Internet"), false, true )->treeItem();

#define NOT_SELECTABLE(w) w->setFlags( w->flags() ^ Qt::ItemIsSelectable );
    NOT_SELECTABLE( mycomp );
    NOT_SELECTABLE( devices );
    NOT_SELECTABLE( lan );
    NOT_SELECTABLE( internet );
#undef NOT_SELECTABLE

    /* SD subnodes */
    char **ppsz_longnames;
    int *p_categories;
    char **ppsz_names = vlc_sd_GetNames( THEPL, &ppsz_longnames, &p_categories );
    if( !ppsz_names )
        return;

    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
    int *p_category = p_categories;
    for( ; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++ )
    {
        //msg_Dbg( p_intf, "Adding a SD item: %s", *ppsz_longname );

        PLSelItem *selItem;
        QIcon icon;
        QString name( *ppsz_name );
        switch( *p_category )
        {
        case SD_CAT_INTERNET:
            {
            selItem = addItem( SD_TYPE, *ppsz_longname, false, false, internet );
            if( name.startsWith( "podcast" ) )
            {
                selItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
                selItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
                CONNECT( selItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
                podcastsParent = selItem->treeItem();
                icon = QIcon( ":/sidebar/podcast" );
            }
            else if ( name.startsWith( "lua{" ) )
            {
                int i_head = name.indexOf( "sd='" ) + 4;
                int i_tail = name.indexOf( '\'', i_head );
                QString iconname = QString( ":/sidebar/sd/%1" ).arg( name.mid( i_head, i_tail - i_head ) );
                QResource resource( iconname );
                if ( !resource.isValid() )
                    icon = QIcon( ":/sidebar/network" );
                else
                    icon = QIcon( iconname );
            }
            }
            break;
        case SD_CAT_DEVICES:
            name = name.mid( 0, name.indexOf( '{' ) );
            selItem = addItem( SD_TYPE, *ppsz_longname, false, false, devices );
            if ( name == "xcb_apps" )
                icon = QIcon( ":/sidebar/screen" );
            else if ( name == "mtp" )
                icon = QIcon( ":/sidebar/mtp" );
            else if ( name == "disc" )
                icon = QIcon( ":/sidebar/disc" );
            else
                icon = QIcon( ":/sidebar/capture" );
            break;
        case SD_CAT_LAN:
            selItem = addItem( SD_TYPE, *ppsz_longname, false, false, lan );
            icon = QIcon( ":/sidebar/lan" );
            break;
        case SD_CAT_MYCOMPUTER:
            name = name.mid( 0, name.indexOf( '{' ) );
            selItem = addItem( SD_TYPE, *ppsz_longname, false, false, mycomp );
            if ( name == "video_dir" )
                icon = QIcon( ":/sidebar/movie" );
            else if ( name == "audio_dir" )
                icon = QIcon( ":/sidebar/music" );
            else if ( name == "picture_dir" )
                icon = QIcon( ":/sidebar/pictures" );
            else
                icon = QIcon( ":/sidebar/movie" );
            break;
        default:
            selItem = addItem( SD_TYPE, *ppsz_longname );
        }
Ejemplo n.º 7
0
int Desktop::handle(int event) {
	switch(event) {
		case FL_FOCUS:
		case FL_UNFOCUS:
		case FL_SHORTCUT:
			return 1;

		case FL_PUSH: {
			/*
			 * First check where we clicked. If we do it on desktop unfocus any possible focused childs, and handle
			 * specific clicks. Otherwise, do rest for childs.
			 */
			Fl_Widget* clicked = Fl::belowmouse();
			
			if(NOT_SELECTABLE(clicked)) {
				//E_DEBUG(E_STRLOC ": DESKTOP CLICK !!!\n");
				if(!selectionbuf.empty()) {
					/*
					 * Only focused are in selectionbuf, so this is fine to do; also will prevent 
					 * full redraw when is clicked on desktop
					 */
					unfocus_all();
					selectionbuf.clear();
				}

				/* track position so moving can be deduced */
				if(Fl::event_button() == 1) {
					selbox->x = Fl::event_x();
					selbox->y = Fl::event_y();
				} else if(Fl::event_button() == 3) {
					last_px = Fl::event_x();
					last_py = Fl::event_y();

					damage(EDE_DESKTOP_DAMAGE_OVERLAY);
					const edelib::MenuItem* item = dmenu->menu()->popup(Fl::event_x(), Fl::event_y());
					dmenu->picked(item);
				}

				return 1;
			}

			/* from here, all events are managed for icons */
			DesktopIcon* tmp_icon = (DesktopIcon*)clicked;

			/* do no use assertion on this, since fltk::belowmouse() can miss our icon */
			if(!tmp_icon) return 1;

			if(SELECTION_MULTI) {
				Fl::event_is_click(0);
				select(tmp_icon);
				return 1;
			} else if(SELECTION_SINGLE) {
				if(!in_selection(tmp_icon)) {
					select_only(tmp_icon);
				}
			} else if(Fl::event_button() == 3) {
				select_only(tmp_icon);
			}

			/* 
			 * Let child handle the rest.
			 * Also prevent click on other mouse buttons during move.
			 */
			if(!moving)
				tmp_icon->handle(FL_PUSH);

			//E_DEBUG(E_STRLOC ": FL_PUSH from desktop\n");
			selection_x = Fl::event_x_root();
			selection_y = Fl::event_y_root();
	
			return 1;
		 }

		case FL_DRAG:
			moving = true;
			if(!selectionbuf.empty()) {
				//E_DEBUG(E_STRLOC ": DRAG icon from desktop\n");
				move_selection(Fl::event_x_root(), Fl::event_y_root(), false);
			} else {
				//E_DEBUG(E_STRLOC ": DRAG from desktop\n");
				/*
				 * Moving is started with pushed button.
				 * From this point selection box is created and is rolled until release
				 */
				if(selbox->x != 0 || selbox->y != 0) {
					selbox->w = Fl::event_x() - selbox->x;
					selbox->h = Fl::event_y() - selbox->y;

					selbox->show = true;

					/* see if there some icons inside selection area */
					select_in_area();

					/* redraw selection box */
					damage(EDE_DESKTOP_DAMAGE_OVERLAY);
				}
			}

			return 1;

		case FL_RELEASE:
			//E_DEBUG(E_STRLOC ": RELEASE from desktop\n");
			//E_DEBUG(E_STRLOC ": clicks: %i\n", Fl::event_is_click());

			if(selbox->show) {
				selbox->x = selbox->y = selbox->w = selbox->h = 0;
				selbox->show = false;
				damage(EDE_DESKTOP_DAMAGE_OVERLAY);

				/*
				 * Now pickup those who are in is_focused() state.
				 *
				 * Possible flickers due overlay will be later removed when is called move_selection(), which 
				 * will in turn redraw icons again after position them.
				 */
				if(!selectionbuf.empty())
					selectionbuf.clear();

				DesktopIcon *o;
				for(int i = 0; i < children(); i++) {
					if(NOT_SELECTABLE(child(i))) continue;

					o = (DesktopIcon*)child(i);
					if(o->is_focused())
						select(o, false);
				}

				return 1;
			}

			if(!selectionbuf.empty() && moving)
				move_selection(Fl::event_x_root(), Fl::event_y_root(), true);

			/* 
			 * Do not send FL_RELEASE during move
			 * TODO: should be alowed FL_RELEASE to multiple icons? (aka. run command for all selected icons)?
			 */
			if(selectionbuf.size() == 1 && !moving)
				selectionbuf.front()->handle(FL_RELEASE);

			moving = false;
			return 1;

		case FL_DND_ENTER:
		case FL_DND_DRAG:
		case FL_DND_LEAVE:
			return 1;

		case FL_DND_RELEASE: {
			DesktopIcon* di = below_mouse(Fl::event_x(), Fl::event_y());
			if(di) return di->handle(event);
			return 1;
		}

		case FL_PASTE: {
			DesktopIcon* di = below_mouse(Fl::event_x(), Fl::event_y());
			if(di) return di->handle(event);
			return 1;
		}

		case FL_ENTER:
		case FL_LEAVE:
		case FL_MOVE:
			return EDE_DESKTOP_WINDOW::handle(event);

		default:
			break;
	}

	return 0;
}
Ejemplo n.º 8
0
void PLSelector::createItems()
{
    /* PL */
    playlistItem = putPLData( addItem( PL_ITEM_TYPE, N_("Playlist"), true ),
                              THEPL->p_playing );
    playlistItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PL ) );
    setCurrentItem( playlistItem->treeItem() );

    /* ML */
    PLSelItem *ml = putPLData( addItem( PL_ITEM_TYPE, N_("Media Library"), true ),
                              THEPL->p_media_library );
    ml->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_ML ) );

#ifdef MEDIA_LIBRARY
    /* SQL ML */
    addItem( SQL_ML_TYPE, "SQL Media Library" )->treeItem();
#endif

    /* SD nodes */
    QTreeWidgetItem *mycomp = addItem( CATEGORY_TYPE, N_("My Computer") )->treeItem();
    QTreeWidgetItem *devices = addItem( CATEGORY_TYPE, N_("Devices") )->treeItem();
    QTreeWidgetItem *lan = addItem( CATEGORY_TYPE, N_("Local Network") )->treeItem();
    QTreeWidgetItem *internet = addItem( CATEGORY_TYPE, N_("Internet") )->treeItem();

#define NOT_SELECTABLE(w) w->setFlags( w->flags() ^ Qt::ItemIsSelectable );
    NOT_SELECTABLE( mycomp );
    NOT_SELECTABLE( devices );
    NOT_SELECTABLE( lan );
    NOT_SELECTABLE( internet );
#undef NOT_SELECTABLE

    /* SD subnodes */
    char **ppsz_longnames;
    int *p_categories;
    char **ppsz_names = vlc_sd_GetNames( THEPL, &ppsz_longnames, &p_categories );
    if( !ppsz_names )
        return;

    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
    int *p_category = p_categories;
    for( ; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++ )
    {
        //msg_Dbg( p_intf, "Adding a SD item: %s", *ppsz_longname );

        PLSelItem *selItem;
        switch( *p_category )
        {
        case SD_CAT_INTERNET:
            {
            selItem = addItem( SD_TYPE, *ppsz_longname, false, internet );
            if( !strncmp( *ppsz_name, "podcast", 7 ) )
            {
                selItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
                selItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
                CONNECT( selItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
                podcastsParent = selItem->treeItem();
            }
            }
            break;
        case SD_CAT_DEVICES:
            selItem = addItem( SD_TYPE, *ppsz_longname, false, devices );
            break;
        case SD_CAT_LAN:
            selItem = addItem( SD_TYPE, *ppsz_longname, false, lan );
            break;
        case SD_CAT_MYCOMPUTER:
            selItem = addItem( SD_TYPE, *ppsz_longname, false, mycomp );
            break;
        default:
            selItem = addItem( SD_TYPE, *ppsz_longname );
        }

        putSDData( selItem, *ppsz_name, *ppsz_longname );
        free( *ppsz_name );
        free( *ppsz_longname );
    }