@ -22,6 +22,8 @@
// TQt
// TQt
# include <tqregexp.h>
# include <tqregexp.h>
# include <tqdbusobjectpath.h>
# include <tqdbusobjectpath.h>
# include <tqapplication.h>
# include <tqthread.h>
// TDE
// TDE
# include <tdeio/renamedlg.h>
# include <tdeio/renamedlg.h>
@ -33,6 +35,48 @@
# include "file_chooser_portal.h"
# include "file_chooser_portal.h"
# include "file_chooser_portal.moc"
# include "file_chooser_portal.moc"
class DialogResultSender : public TQThread
{
public :
DialogResultSender ( KFileDialog * dlg , int asyncCallId , TDEFileChooserPortal * portal , TQT_DBusAsyncCallback callback )
: TQThread ( ) , m_dlg ( dlg ) , m_asyncCallId ( asyncCallId ) , m_portal ( portal ) , m_callback ( callback )
{ }
~ DialogResultSender ( )
{
wait ( ) ;
}
void run ( )
{
if ( ! m_dlg ) return ;
while ( m_dlg - > isVisible ( ) )
{
usleep ( 1000 ) ;
}
KURL : : List urllist = m_dlg - > selectedURLs ( ) ;
TQMap < TQString , TQT_DBusVariant > results ;
TQT_DBusDataList urls = kurl_list_to_datalist ( urllist ) ;
TQT_DBusVariant var = TQT_DBusData : : fromList ( urls ) . getAsVariantData ( ) . toVariant ( ) ;
results . insert ( " uris " , var ) ;
TQ_UINT32 response = urllist . isEmpty ( ) ? 1 : 0 ;
( m_portal - > * m_callback ) ( m_asyncCallId , response , results ) ;
m_dlg - > deleteLater ( ) ;
}
private :
KFileDialog * m_dlg ;
int m_asyncCallId ;
TDEFileChooserPortal * m_portal ;
TQT_DBusAsyncCallback m_callback ;
} ;
TDEFileChooserPortal : : TDEFileChooserPortal ( TQT_DBusConnection & connection )
TDEFileChooserPortal : : TDEFileChooserPortal ( TQT_DBusConnection & connection )
: m_connection ( connection )
: m_connection ( connection )
{ }
{ }
@ -40,14 +84,12 @@ TDEFileChooserPortal::TDEFileChooserPortal(TQT_DBusConnection &connection)
TDEFileChooserPortal : : ~ TDEFileChooserPortal ( )
TDEFileChooserPortal : : ~ TDEFileChooserPortal ( )
{ }
{ }
bool TDEFileChooserPortal : : OpenFile ( const TQT_DBusObjectPath & handle ,
void TDEFileChooserPortal : : OpenFileAsync ( int asyncCallId ,
const TQT_DBusObjectPath & handle ,
const TQString & app_id ,
const TQString & app_id ,
const TQString & parent_window ,
const TQString & parent_window ,
const TQString & title ,
const TQString & title ,
const TQMap < TQString , TQT_DBusVariant > & options ,
const TQT_DBusVariantMap & options )
TQ_UINT32 & response ,
TQMap < TQString , TQT_DBusVariant > & results ,
TQT_DBusError & error )
{
{
FileDialogOpts opts ;
FileDialogOpts opts ;
@ -70,17 +112,16 @@ bool TDEFileChooserPortal::OpenFile(const TQT_DBusObjectPath& handle,
opts . windowId = parse_window_id ( parent_window ) ;
opts . windowId = parse_window_id ( parent_window ) ;
return execFileDialog ( opts , handle , response , results , error ) ;
// Execute dialog
execFileDialog ( & TDEFileChooserPortal : : OpenFileAsyncReply , asyncCallId , opts , handle ) ;
}
}
bool TDEFileChooserPortal : : SaveFile ( const TQT_DBusObjectPath & handle ,
void TDEFileChooserPortal : : SaveFileAsync ( int asyncCallId ,
const TQT_DBusObjectPath & handle ,
const TQString & app_id ,
const TQString & app_id ,
const TQString & parent_window ,
const TQString & parent_window ,
const TQString & title ,
const TQString & title ,
const TQMap < TQString , TQT_DBusVariant > & options ,
const TQT_DBusVariantMap & options )
TQ_UINT32 & response ,
TQMap < TQString , TQT_DBusVariant > & results ,
TQT_DBusError & error )
{
{
FileDialogOpts opts ;
FileDialogOpts opts ;
@ -109,7 +150,7 @@ bool TDEFileChooserPortal::SaveFile(const TQT_DBusObjectPath& handle,
opts . windowId = parse_window_id ( parent_window ) ;
opts . windowId = parse_window_id ( parent_window ) ;
return execFileDialog ( opts , handle , response , results , error ) ;
execFileDialog ( & TDEFileChooserPortal : : SaveFileAsyncReply , asyncCallId , opts , handle ) ;
}
}
bool TDEFileChooserPortal : : SaveFiles ( const TQT_DBusObjectPath & handle ,
bool TDEFileChooserPortal : : SaveFiles ( const TQT_DBusObjectPath & handle ,
@ -211,11 +252,10 @@ bool TDEFileChooserPortal::handleSignalSend(const TQT_DBusMessage& reply) {
return true ;
return true ;
}
}
bool TDEFileChooserPortal : : execFileDialog ( FileDialogOpts options ,
void TDEFileChooserPortal : : execFileDialog ( TQT_DBusAsyncCallback callback ,
const TQT_DBusObjectPath & handle ,
int asyncCallId ,
TQ_UINT32 & response ,
FileDialogOpts options ,
TQMap < TQString , TQT_DBusVariant > & results ,
const TQT_DBusObjectPath & handle )
TQT_DBusError & error )
{
{
KFileDialog * dialog = new KFileDialog ( options . startDir , TQString : : null ,
KFileDialog * dialog = new KFileDialog ( options . startDir , TQString : : null ,
nullptr , " xdg-tde-file-chooser " ,
nullptr , " xdg-tde-file-chooser " ,
@ -243,15 +283,11 @@ bool TDEFileChooserPortal::execFileDialog(FileDialogOpts options,
if ( options . windowId > 0 ) KWin : : setMainWindow ( dialog , options . windowId ) ;
if ( options . windowId > 0 ) KWin : : setMainWindow ( dialog , options . windowId ) ;
if ( dialog - > exec ( ) = = TQDialog : : Accepted )
// return dialog->selectedURLs();
{
response = 0 ;
DialogResultSender * sender = new DialogResultSender ( dialog , asyncCallId , this , callback ) ;
TQT_DBusDataList urls = kurl_list_to_datalist ( dialog - > selectedURLs ( ) ) ;
dialog - > show ( ) ;
TQT_DBusVariant var = TQT_DBusData : : fromList ( urls ) . getAsVariantData ( ) . toVariant ( ) ;
sender - > start ( ) ;
results . insert ( " uris " , var ) ;
}
else response = 1 ;
return true ;
}
}
TQString TDEFileChooserPortal : : parseFilter ( const TQT_DBusData data )
TQString TDEFileChooserPortal : : parseFilter ( const TQT_DBusData data )