Smb4K – Samba (SMB) share advanced browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
6.9KB

  1. /***************************************************************************
  2. smb4kshareslistview - This is the shares list view of Smb4K.
  3. -------------------
  4. begin : Sa Jun 30 2007
  5. copyright : (C) 2007 by Alexander Reinholdt
  6. email : dustpuppy@users.berlios.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. * This program is distributed in the hope that it will be useful, but *
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  17. * General Public License for more details. *
  18. * *
  19. * You should have received a copy of the GNU General Public License *
  20. * along with this program; if not, write to the *
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
  22. * MA 02110-1301 USA *
  23. ***************************************************************************/
  24. // TQt includes
  25. #include <tqtimer.h>
  26. // KDE includes
  27. #include <tdelocale.h>
  28. #include <kurl.h>
  29. #include <tdeio/job.h>
  30. #include <tdeversion.h>
  31. #include <kdebug.h>
  32. // application specific includes
  33. #include "smb4kshareslistview.h"
  34. #include "smb4kshareslistviewitem.h"
  35. #include "smb4kshareslistviewtooltip.h"
  36. #include "../core/smb4ksettings.h"
  37. Smb4KSharesListView::Smb4KSharesListView( TQWidget *parent, const char *name )
  38. : TDEListView( parent, name )
  39. {
  40. setSelectionModeExt( TDEListView::Single );
  41. setAllColumnsShowFocus( false );
  42. setItemsMovable( false );
  43. setAcceptDrops( true );
  44. // Set up columns
  45. addColumn( i18n( "Item" ) );
  46. addColumn( i18n( "Owner" ) );
  47. #ifndef __FreeBSD__
  48. addColumn( i18n( "Login" ) );
  49. #endif
  50. addColumn( i18n( "File System" ) );
  51. addColumn( i18n( "Free" ) );
  52. addColumn( i18n( "Used" ) );
  53. addColumn( i18n( "Total" ) );
  54. addColumn( i18n( "Usage" ) );
  55. // Set alignment
  56. setColumnAlignment( Free, TQt::AlignRight );
  57. setColumnAlignment( Used, TQt::AlignRight );
  58. setColumnAlignment( Total, TQt::AlignRight );
  59. setColumnAlignment( Usage, TQt::AlignRight );
  60. m_tooltip = NULL;
  61. // Connections:
  62. connect( this, TQT_SIGNAL( pressed( TQListViewItem * ) ),
  63. this, TQT_SLOT( slotPressed( TQListViewItem * ) ) );
  64. }
  65. Smb4KSharesListView::~Smb4KSharesListView()
  66. {
  67. if ( m_tooltip )
  68. {
  69. delete m_tooltip;
  70. }
  71. }
  72. void Smb4KSharesListView::updateToolTip()
  73. {
  74. if ( !m_tooltip )
  75. {
  76. return;
  77. }
  78. m_tooltip->update();
  79. }
  80. KURLDrag *Smb4KSharesListView::dragObject()
  81. {
  82. // Get the KURL of the item that is to be dragged:
  83. KURL url = KURL( static_cast<Smb4KSharesListViewItem *>( currentItem() )->shareObject()->canonicalPath() );
  84. KURLDrag *drag = new KURLDrag( KURL::List( url ), this );
  85. drag->setPixmap( DesktopIcon( "folder" ) );
  86. // drag->dragCopy();
  87. return drag;
  88. }
  89. void Smb4KSharesListView::startDrag()
  90. {
  91. if ( !Smb4KSettings::enableDragSupport() )
  92. {
  93. return;
  94. }
  95. TDEListView::startDrag();
  96. }
  97. void Smb4KSharesListView::contentsDragEnterEvent( TQDragEnterEvent *e )
  98. {
  99. e->accept( Smb4KSettings::enableDropSupport() );
  100. }
  101. void Smb4KSharesListView::contentsDragMoveEvent( TQDragMoveEvent *e )
  102. {
  103. TQListViewItem *item = itemAt( contentsToViewport( e->pos() ) );
  104. e->accept( Smb4KSettings::enableDropSupport() && item );
  105. }
  106. void Smb4KSharesListView::contentsDropEvent( TQDropEvent *e )
  107. {
  108. TQListViewItem *item = itemAt( contentsToViewport( e->pos() ) );
  109. KURL::List src;
  110. // Do we have to stop here?
  111. if ( !Smb4KSettings::enableDropSupport() ||
  112. !item ||
  113. !KURLDrag::decode( e, src ) )
  114. {
  115. e->ignore();
  116. return;
  117. }
  118. KURL dest;
  119. dest.setPath( static_cast<Smb4KSharesListViewItem *>( item )->shareObject()->canonicalPath() );
  120. // Deny dropping if we dropped something on itself.
  121. // This was inspired by KonqOperations::doDrop() function.
  122. for ( KURL::List::Iterator it = src.begin(); it != src.end(); ++it )
  123. {
  124. if ( dest.equals( *it, true ) )
  125. {
  126. if ( e->source() == this || TQT_BASE_OBJECT(e->source()->parent()) == TQT_BASE_OBJECT(this) )
  127. {
  128. e->ignore();
  129. return;
  130. }
  131. }
  132. }
  133. // We only allow copying:
  134. TDEIO::CopyJob *job = TDEIO::copy( src, dest, true );
  135. job->setAutoErrorHandlingEnabled( true, NULL );
  136. #if TDE_VERSION_MAJOR >= 3 && TDE_VERSION_MINOR >= 5
  137. job->setAutoWarningHandlingEnabled( true );
  138. #endif
  139. }
  140. void Smb4KSharesListView::contentsMouseMoveEvent( TQMouseEvent *e )
  141. {
  142. m_pos = e->globalPos();
  143. Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( itemAt( contentsToViewport( e->pos() ) ) );
  144. if ( item )
  145. {
  146. if ( m_tooltip )
  147. {
  148. // Check if tool tip is still valid:
  149. if ( m_tooltip->item() != item )
  150. {
  151. delete m_tooltip;
  152. if ( hasMouse() && Smb4KSettings::showShareToolTip() )
  153. {
  154. m_tooltip = new Smb4KSharesListViewToolTip( item );
  155. TQTimer::singleShot( 2000, this, TQT_SLOT( slotShowToolTip() ) );
  156. }
  157. else
  158. {
  159. m_tooltip = NULL;
  160. }
  161. }
  162. else
  163. {
  164. // Do nothing
  165. }
  166. }
  167. else
  168. {
  169. // Create new tool tip:
  170. if ( hasMouse() && Smb4KSettings::showShareToolTip() )
  171. {
  172. m_tooltip = new Smb4KSharesListViewToolTip( item );
  173. TQTimer::singleShot( 2000, this, TQT_SLOT( slotShowToolTip() ) );
  174. }
  175. else
  176. {
  177. // Do nothing
  178. }
  179. }
  180. }
  181. else
  182. {
  183. if ( m_tooltip )
  184. {
  185. delete m_tooltip;
  186. m_tooltip = NULL;
  187. }
  188. }
  189. TDEListView::contentsMouseMoveEvent( e );
  190. }
  191. /////////////////////////////////////////////////////////////////////////////
  192. // TQT_SLOT IMPLEMENTATIONS
  193. /////////////////////////////////////////////////////////////////////////////
  194. void Smb4KSharesListView::slotPressed( TQListViewItem *item )
  195. {
  196. if ( m_tooltip )
  197. {
  198. delete m_tooltip;
  199. m_tooltip = NULL;
  200. }
  201. if ( !item )
  202. {
  203. // Clear the selection if the user clicked onto the
  204. // viewport:
  205. clearSelection();
  206. }
  207. else
  208. {
  209. // Do nothing
  210. }
  211. }
  212. void Smb4KSharesListView::slotShowToolTip()
  213. {
  214. if ( m_tooltip && hasMouse() && Smb4KSettings::showShareToolTip() &&
  215. (m_tooltip->item() == static_cast<Smb4KSharesListViewItem *>( itemAt( viewport()->mapFromGlobal( m_pos ) ) )) )
  216. {
  217. m_tooltip->showTip( m_pos );
  218. }
  219. else
  220. {
  221. delete m_tooltip;
  222. m_tooltip = NULL;
  223. }
  224. }
  225. #include "smb4kshareslistview.moc"