summaryrefslogtreecommitdiffstats
path: root/konqueror/sidebar/trees/konqsidebar_tree.cpp
blob: fc53039b6aacbaffdf96fca2479477ab6440a107 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "konqsidebar_tree.h"
#include "konqsidebar_tree.moc"
#include "konq_sidebartree.h"
#include <kdebug.h>
#include <kstandarddirs.h>
#include <ksimpleconfig.h>
#include <kinputdialog.h>
#include <kiconloader.h>
#include <klistviewsearchline.h>

#include <tqclipboard.h>
#include <tqdragobject.h>
#include <tqtoolbutton.h>
#include <tqvbox.h>
#include <tqapplication.h>

KonqSidebar_Tree::KonqSidebar_Tree(KInstance *instance,TQObject *parent,TQWidget *widgetParent, TQString &desktopName_, const char* name):
                   KonqSidebarPlugin(instance,parent,widgetParent,desktopName_,name)
	{
		KSimpleConfig ksc(desktopName_);
		ksc.setGroup("Desktop Entry");
		int virt= ( (ksc.readEntry("X-KDE-TreeModule","")=="Virtual") ?VIRT_Folder:VIRT_Link);
		if (virt==1) desktopName_=ksc.readEntry("X-KDE-RelURL","");

		widget = new TQVBox(widgetParent);

		if (ksc.readBoolEntry("X-KDE-SearchableTreeModule",false)) {
			TQHBox* searchline = new TQHBox(widget);
			searchline->setSpacing(KDialog::spacingHint());
			tree=new KonqSidebarTree(this,widget,virt,desktopName_);
			TQToolButton *clearSearch = new TQToolButton(searchline);
			clearSearch->setTextLabel(i18n("Clear Search"), true);
			clearSearch->setIconSet(SmallIconSet(TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"));
			TQLabel* slbl = new TQLabel(i18n("Se&arch:"), searchline);
			KListViewSearchLine* listViewSearch = new KListViewSearchLine(searchline,tree);
			slbl->setBuddy(listViewSearch);
			connect(clearSearch, TQT_SIGNAL(pressed()), listViewSearch, TQT_SLOT(clear()));
		}
		else
			tree=new KonqSidebarTree(this,widget,virt,desktopName_);

    		connect(tree, TQT_SIGNAL( openURLRequest( const KURL &, const KParts::URLArgs &)),
			this,TQT_SIGNAL( openURLRequest( const KURL &, const KParts::URLArgs &)));

		connect(tree,TQT_SIGNAL(createNewWindow( const KURL &, const KParts::URLArgs &)),
			this,TQT_SIGNAL(createNewWindow( const KURL &, const KParts::URLArgs &)));

		connect(tree,TQT_SIGNAL(popupMenu( const TQPoint &, const KURL &, const TQString &, mode_t )),
			this,TQT_SIGNAL(popupMenu( const TQPoint &, const KURL &, const TQString &, mode_t )));

		connect(tree,TQT_SIGNAL(popupMenu( const TQPoint &, const KFileItemList & )),
			this,TQT_SIGNAL(popupMenu( const TQPoint &, const KFileItemList & )));

		connect(tree,TQT_SIGNAL(enableAction( const char *, bool )),
			this,TQT_SIGNAL(enableAction( const char *, bool)));

        }


KonqSidebar_Tree::~KonqSidebar_Tree(){;}

void* KonqSidebar_Tree::provides(const TQString &) {return 0;}

//void KonqSidebar_Tree::emitStatusBarText (const TQString &) {;}

TQWidget *KonqSidebar_Tree::getWidget(){return widget;}

void KonqSidebar_Tree::handleURL(const KURL &url)
    {
	emit started( 0 );
        tree->followURL( url );
        emit completed();
    }

void KonqSidebar_Tree::cut()
{
    TQDragObject * drag = static_cast<KonqSidebarTreeItem*>(tree->selectedItem())->dragObject( 0L, true );
    if (drag)
        TQApplication::tqclipboard()->setData( drag );
}

void KonqSidebar_Tree::copy()
{
    TQDragObject * drag = static_cast<KonqSidebarTreeItem*>(tree->selectedItem())->dragObject( 0L );
    if (drag)
        TQApplication::tqclipboard()->setData( drag );
}

void KonqSidebar_Tree::paste()
{
    if (tree->currentItem())
        tree->currentItem()->paste();
}

void KonqSidebar_Tree::trash()
{
    if (tree->currentItem())
        tree->currentItem()->trash();
}

void KonqSidebar_Tree::del()
{
    if (tree->currentItem())
        tree->currentItem()->del();
}

void KonqSidebar_Tree::shred()
{
    if (tree->currentItem())
        tree->currentItem()->shred();
}

void KonqSidebar_Tree::rename()
{
    Q_ASSERT( tree->currentItem() );
    if (tree->currentItem())
        tree->currentItem()->rename();
}






extern "C"
{
    KDE_EXPORT void*  create_konqsidebar_tree(KInstance *inst,TQObject *par,TQWidget *widp,TQString &desktopname,const char *name)
    {
        return new KonqSidebar_Tree(inst,par,widp,desktopname,name);
    }
}

extern "C"
{
   KDE_EXPORT bool add_konqsidebar_tree(TQString* fn, TQString*, TQMap<TQString,TQString> *map)
   {
	  KStandardDirs *dirs=KGlobal::dirs();
	  TQStringList list=dirs->findAllResources("data","konqsidebartng/dirtree/*.desktop",false,true);
	  TQStringList names;
	  for (TQStringList::ConstIterator it=list.begin();it!=list.end();++it)
	  {
		KSimpleConfig sc(*it);
		sc.setGroup("Desktop Entry");
		names<<sc.readEntry("Name");
	  }

	TQString item = KInputDialog::getItem( i18n( "Select Type" ),
		i18n( "Select type:" ), names );
	if (!item.isEmpty())
		{
			int id=names.tqfindIndex( item );
			if (id==-1) return false;
			KSimpleConfig ksc2(*list.tqat(id));
			ksc2.setGroup("Desktop Entry");
		        map->insert("Type","Link");
			map->insert("Icon",ksc2.readEntry("Icon"));
			map->insert("Name",ksc2.readEntry("Name"));
		 	map->insert("Open","false");
			map->insert("URL",ksc2.readEntry("X-KDE-Default-URL"));
			map->insert("X-KDE-KonqSidebarModule","konqsidebar_tree");
			map->insert("X-KDE-TreeModule",ksc2.readEntry("X-KDE-TreeModule"));
			map->insert("X-KDE-TreeModule-ShowHidden",ksc2.readEntry("X-KDE-TreeModule-ShowHidden"));
			fn->setLatin1("dirtree%1.desktop");
			return true;
		}
	return false;
   }
}