energy/cef/types-download-item.go

289 lines
6.6 KiB
Go
Raw Normal View History

2023-02-28 09:55:20 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package cef
import (
"github.com/energye/energy/v2/cef/internal/def"
2023-05-31 18:00:34 +08:00
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/common/imports"
2023-02-28 09:55:20 +08:00
"github.com/energye/golcl/lcl/api"
"time"
"unsafe"
)
2023-03-04 11:58:35 +08:00
// DownloadItemRef -> ICefDownloadItem
var DownloadItemRef downloadItem
// downloadItem
type downloadItem uintptr
func (*downloadItem) UnWrap(data *ICefDownloadItem) *ICefDownloadItem {
var result uintptr
imports.Proc(def.CefDownloadItemRef_UnWrap).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
2023-03-04 11:58:35 +08:00
data.instance = unsafe.Pointer(result)
return data
}
2023-02-28 09:55:20 +08:00
func (m *ICefDownloadItem) Instance() uintptr {
return uintptr(m.instance)
}
func (m *ICefDownloadItem) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsValid).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoBool(r1)
}
func (m *ICefDownloadItem) IsInProgress() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsInProgress).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoBool(r1)
}
func (m *ICefDownloadItem) IsComplete() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsComplete).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoBool(r1)
}
func (m *ICefDownloadItem) IsCanceled() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsCanceled).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoBool(r1)
}
func (m *ICefDownloadItem) CurrentSpeed() int64 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_CurrentSpeed).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return int64(r1)
}
func (m *ICefDownloadItem) PercentComplete() int32 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_PercentComplete).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return int32(r1)
}
func (m *ICefDownloadItem) TotalBytes() int64 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_TotalBytes).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return int64(r1)
}
func (m *ICefDownloadItem) ReceivedBytes() int64 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_ReceivedBytes).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return int64(r1)
}
func (m *ICefDownloadItem) StartTime() time.Time {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return time.Time{}
}
2023-02-28 09:55:20 +08:00
var result uintptr
imports.Proc(def.CefDownloadItem_StartTime).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
2023-02-28 09:55:20 +08:00
return common.DDateTimeToGoDateTime(*(*float64)(unsafe.Pointer(result)))
}
func (m *ICefDownloadItem) EndTime() time.Time {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return time.Time{}
}
2023-02-28 09:55:20 +08:00
var result uintptr
imports.Proc(def.CefDownloadItem_EndTime).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
2023-02-28 09:55:20 +08:00
return common.DDateTimeToGoDateTime(*(*float64)(unsafe.Pointer(result)))
}
func (m *ICefDownloadItem) FullPath() string {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_FullPath).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoStr(r1)
}
func (m *ICefDownloadItem) Id() uint32 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_Id).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return uint32(r1)
}
func (m *ICefDownloadItem) Url() string {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_Url).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoStr(r1)
}
func (m *ICefDownloadItem) OriginalUrl() string {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_OriginalUrl).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoStr(r1)
}
func (m *ICefDownloadItem) SuggestedFileName() string {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_SuggestedFileName).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoStr(r1)
}
func (m *ICefDownloadItem) ContentDisposition() string {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_ContentDisposition).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoStr(r1)
}
func (m *ICefDownloadItem) MimeType() string {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_MimeType).Call(m.Instance())
2023-02-28 09:55:20 +08:00
return api.GoStr(r1)
}
//State 下载状态 -1:下载之前 0:下载中 1:下载取消 2:下载完成
func (m *ICefDownloadItem) State() int32 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
2023-02-28 09:55:20 +08:00
if m.IsComplete() {
return 2
} else if m.IsCanceled() {
return 1
} else if m.IsInProgress() {
return 0
} else {
return -1
}
}
2023-03-13 18:12:55 +08:00
func (m *ICefDownloadItem) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
2023-05-31 17:41:14 +08:00
// DownloadItemCallbackRef => ICefDownloadItemCallback
2023-03-13 18:12:55 +08:00
var DownloadItemCallbackRef downloadItemCallback
type downloadItemCallback uintptr
func (*downloadItemCallback) UnWrap(data *ICefDownloadItemCallback) *ICefDownloadItemCallback {
var result uintptr
imports.Proc(def.CefDownloadItemCallbackRef_Pause).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
2023-03-13 18:12:55 +08:00
return &ICefDownloadItemCallback{instance: unsafe.Pointer(result)}
}
2023-02-28 09:55:20 +08:00
func (m *ICefDownloadItemCallback) Instance() uintptr {
return uintptr(m.instance)
}
2023-05-31 17:41:14 +08:00
func (m *ICefDownloadItemCallback) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return m.instance != nil
}
2023-02-28 09:55:20 +08:00
/*
2023-02-28 21:15:11 +08:00
Cancel 取消下载 仅在回调函数中使用
2023-02-28 09:55:20 +08:00
*/
func (m *ICefDownloadItemCallback) Cancel() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CefDownloadItemCallback_Cancel).Call(m.Instance())
2023-02-28 09:55:20 +08:00
}
/*
2023-02-28 21:15:11 +08:00
Pause 暂停 仅在回调函数中使用
2023-02-28 09:55:20 +08:00
*/
func (m *ICefDownloadItemCallback) Pause() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CefDownloadItemCallback_Pause).Call(m.Instance())
2023-02-28 09:55:20 +08:00
}
/*
2023-02-28 21:15:11 +08:00
Resume 恢复下载 仅在回调函数中使用
2023-02-28 09:55:20 +08:00
*/
func (m *ICefDownloadItemCallback) Resume() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CefDownloadItemCallback_Resume).Call(m.Instance())
2023-02-28 09:55:20 +08:00
}
2023-03-13 18:12:55 +08:00
func (m *ICefDownloadItemCallback) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
2023-02-28 09:55:20 +08:00
func (m *ICefBeforeDownloadCallback) Instance() uintptr {
return uintptr(m.instance)
}
2023-05-31 17:41:14 +08:00
func (m *ICefBeforeDownloadCallback) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return m.instance != nil
}
2023-02-28 09:55:20 +08:00
// Cont
2023-02-28 21:15:11 +08:00
// 设置下载目录 仅在回调函数中使用
2023-02-28 09:55:20 +08:00
//
// downloadPath 设置完整的下载目录, 包含文件名
//
// showDialog 弹出保存目录窗口
func (m *ICefBeforeDownloadCallback) Cont(downloadPath string, showDialog bool) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CefBeforeDownloadCallback_Cont).Call(m.Instance(), api.PascalStr(downloadPath), api.PascalBool(showDialog))
2023-02-28 09:55:20 +08:00
}
2023-03-13 18:12:55 +08:00
func (m *ICefBeforeDownloadCallback) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}